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

OnEachTick Enter or Exist on Trade.

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

    OnEachTick Enter or Exist on Trade.

    OnEachTick :
    - Purpose of the blow strategy is to enter in the Live Candle when it is forming ( Live Bar only) and Place the trade on the Green or Red candle.
    - Calculate = Calculate.OnEachTick;
    - it will exit the position when next forming candle will become Red or Green.

    Result :
    Unfortunately, it is working only once is it activated and nothing is happening after that.
    It is in Testing environment currently.

    Any suggestions, Please welcome and Thanks in advance.
    ================================================== ================================================== ====

    if( Close[0] > Open[0] ){

    if(IsFirstTickOfBar == true ){
    Print("Green" + Position.MarketPosition);
    if(Position.MarketPosition == MarketPosition.Short){
    ExitShort(1);
    Print("ExitShort " + Time[0] + " Current Open-->" + Open[0] + " Current Close " + Close[0]);
    }

    //SetStopLoss(CalculationMode.Ticks, 1);
    if(Position.MarketPosition != MarketPosition.Long){
    EnterLong(1, "GREEN "+ DateTime.Now );
    Print("Buy Signal " + Time[0] + " Current Open-->" + Open[0] + " Current Close " + Close[0]);
    }
    }
    }

    if( Close[0] < Open[0] ){

    if(IsFirstTickOfBar == true){
    Print("RED" + Position.MarketPosition);
    if(Position.MarketPosition == MarketPosition.Long){
    ExitLong(1);
    Print("ExitLong " + Time[0] + " Current Open-->" + Open[0] + " Current Close " + Close[0]);
    }

    //SetStopLoss(CalculationMode.Ticks, 1);
    if(Position.MarketPosition != MarketPosition.Short){
    EnterShort(1, "Short " + DateTime.Now);
    Print("RED Signal Entershort " + Time[0] + " Current Open-->" + Open[0] + " Current Close " + Close[0]);
    }

    }
    }

    #2
    Hello yogeshdhan78,

    Thank you for your post.

    You have 2 issues here. First, you are calling both an Exit and an Entry order on each first tick of bar, which will result in a doubled position. If you are simply reversing position, all you need to do is call an Entry order in the opposite direction. Remove the exit orders to resolve this.

    The other larger issue, and why you aren't seeing real time trades, is that on the first tick of a bar, the close of that bar will be equal to the open - it's the first tick of the bar so we don't yet know if the bar will be a green or a red bar - it has no direction at that point. You'd need to change those conditions to see real time trades taken. The reason you see historical trades is that on historical data, we only know the OHLC of the bar, so it will be evaluated when the bar closes and any orders would take place on the bar after being triggered as it is essentially running OnBarClose on the historical data of the chart.

    You would need to assess the previous bar and then enter on the first tick of the next bar for that to work.

    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by terofs, Yesterday, 04:18 PM
    1 response
    21 views
    0 likes
    Last Post terofs
    by terofs
     
    Started by CommonWhale, Today, 09:55 AM
    1 response
    3 views
    0 likes
    Last Post NinjaTrader_Erick  
    Started by Gerik, Today, 09:40 AM
    2 responses
    7 views
    0 likes
    Last Post Gerik
    by Gerik
     
    Started by RookieTrader, Today, 09:37 AM
    2 responses
    13 views
    0 likes
    Last Post RookieTrader  
    Started by alifarahani, Today, 09:40 AM
    1 response
    7 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Working...
    X