Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Question about the program structure

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Question about the program structure

    I am developing a strategy and I would like to try to separate the trading execution and the trading signal in different classes.

    I have an indicator created by myself. That indicator will provide me the trading signal, for example buy/sell and the sl and tp price.

    I am doing something like this in my strategy class now:

    Code:
    void OnBarUpdate()
    {
       if (condition okay for Long)
       {
          MyIndicator(parameters, ... ).GetLongInfo(ref TP, ref SL);
          SetProfitTarget(..., TP, ...);
          SetStopLoss(..., SL, ...);
          EnterLong(...);
       }
    }
    I would like to create a separate class such as:

    Code:
    if (State == State.DataLoaded)
    {
       myTrader = new MyTestingTrader();
       myTrader.Init(TPSetting, SLSetting, IndicatorSetting);
    }
    
    void OnBarUpdate()
    {
       if (condition okay for Long)
       {
          myTrader.DoLong();
       }
    }
    I try to create a new class like this inside the indicator folder:

    Code:
    namespace NinjaTrader.NinjaScript.Indicators
    {
        class MyTestingTrader
       {
       }
    
       void DoLong()
       {
          MyIndicator(parameters, ... ).GetLongInfo(ref TP, ref SL);
          SetProfitTarget(..., TP, ...);
          SetStopLoss(..., SL, ...);
          EnterLong(...);
       }
    }
    There is 2 problems, it seems that I cannot get the other indicator and also I don't have those function to handle trading order.

    I would like to ask if there is a way to do this ?
    Thank you very much.

    #2
    For data processing and position management it's possible to pass an indicator or strategy reference to another class.
    https://ninjatrader.com/support/foru...y-or-indicator
    Either subscribe to the state change event in the separate class(dunno how to do that) or invoke a state change method in the class in the strategy or indicator OnStateChange.
    Last edited by MojoJojo; 04-17-2020, 04:26 AM.

    Comment


      #3
      Thank you very much. MojoJojo

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Today, 05:17 AM
      0 responses
      53 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      130 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      70 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      44 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      49 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X