Definition

Allows the user to send and receive custom messages to/from Python code.

 

Note:  The DSTRemoteSendCustomMessage method has two overrides. The first version is for creating models and only sends data to python. The second version is for predicting/inferring models where we can send a custom message as well as receive a message back from Python. The prediction allows python to send back additional information to NinjaTrader in order to decide if we should enter a trade. For example, a confidence level could be sent from python back to NinjaTrader and be used to decide if we should enter a trade.


Create Model Method - DSTRemoteSendCustomMessage(string message)

Predict Model Method - DSTRemoteSendCustomMessage(string message, ref string receivedMessage)

 

Syntax

DSTRemoteSendCustomMessage(string message)
DSTRemoteSendCustomMessage(string message, ref string receivedMessage)

 


 

Parameters

message

string used to pass a message to the python code

receivedMessage

ref string used to pass messages from python back to NinjaTrader


 

 

Examples

ns

Sending a message in a strategy derived from DSTCreateRemoteModelBase, such as DSTCreateRemoteModelTest


public class DSTCreateRemoteModelTest : DSTCreateRemoteModelBase

{


...


   private string GetBarData()

   {

       string sep = ",";

       string sb = string.Empty;


       sb += Open[0] + sep;

       sb += High[0] + sep;

       sb += Low[0] + sep;

       sb += Close[0] + sep;


       return sb.ToString();

   }


   protected override void OnBarUpdate()

   {

       // Please do not change, the DST Library will need to call OnBarUpdate. Add any additional code below this line.

       base.OnBarUpdate();

            

       string barData = GetBarData();

       DSTRemoteSendCustomMessage(barData);

   }

}




 

ns

Sending a message in a strategy derived from DSTPredictRemoteModelBase, such as DSTPredictRemoteModelCustomMessage


public class DSTPredictRemoteModelCustomMessage : DSTPredictRemoteModelBase

{


...


  private string GetBarData()

  {

     string sep = ",";

     string sb = string.Empty;


     sb += Open[0] + sep;

     sb += High[0] + sep;

     sb += Low[0] + sep;

     sb += Close[0] + sep;


     return sb.ToString();

  }


  protected override void OnBarUpdate()

  {

     string msg = "Strategy " + _StrategyId;


     // Please do not change, the DST Library will need to call OnBarUpdate. Add any additional code below this line.

     base.OnBarUpdate();


     string recdMsg = string.Empty;

     string barData = GetBarData();

     msg += ", sending data: " + barData;


     DSTRemoteSendCustomMessage(barData, ref recdMsg);

     msg += ", recd data: " + recdMsg;


     Print(msg);

  }

}
 
 

 









Futures, foreign currency and options trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones financial security or lifestyle. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results.