Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 MacDad, 02-25-2024, 11:48 PM
      7 responses
      158 views
      0 likes
      Last Post loganjarosz123  
      Started by Belfortbucks, Today, 09:29 PM
      0 responses
      7 views
      0 likes
      Last Post Belfortbucks  
      Started by zstheorist, Today, 07:52 PM
      0 responses
      7 views
      0 likes
      Last Post zstheorist  
      Started by pmachiraju, 11-01-2023, 04:46 AM
      8 responses
      151 views
      0 likes
      Last Post rehmans
      by rehmans
       
      Started by mattbsea, Today, 05:44 PM
      0 responses
      6 views
      0 likes
      Last Post mattbsea  
      Working...
      X