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 on BarSinceEntry()

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

    Question on BarSinceEntry()

    I am having a problem with BarSinceEntry()

    It's returning some large numbers that don't seem to make sense?

    The strategy places an order, and then uses barsSinceEntry to adjust the stop technique.

    Here's a code snippet



    Code:
    // Entry logic 
    
    EnterShort(DefaultQuantity, "S2_S");
    PBHigh = High[1] + 2*TickSize; 
    PBHigh = Math.Min(PBHigh,High[0]+(15*TickSize));
    Print(Instrument.FullName+" New Short, Entry is "+ Close.ToString()[0]);
    Print(Instrument.FullName+" New Short, Prior Bar High= "+High.ToString()[1]+ " Stop Loss = "+ PBHigh.ToString());
    SetStopLoss(CalculationMode.Price, PBHigh);
    . . . 
    // Stop Logic
    if (Position.MarketPosition == MarketPosition.Long && FirstTickOfBar)
     {
     Print(Instrument.FullName+" In Long,Bars = "+ BarsSinceEntry().ToString());
     //Set new Stop Loss if (BarsSinceEntry() > 5)
     if ( BarsSinceEntry() >5 ) 
     { 
      ....
     }
     else  Print(Instrument.FullName+" In Long, Less than >5 bars = ");
    And the resulting log/trace. It's just one bar away, but shows 6648 bars since entry.
    fwiw, it seems to work correctly on the strategies first trade, but that's just a hunch at this point. Look for the text 'In Short Bars'

    Code:
    Entered internal PlaceOrder() method at 4/11/2007 10:48:00 AM: Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName=S2_S' FromEntrySignal=''
    ER2 06-07 New Short, Entry is 8
    ER2 06-07 New Short, Prior Bar High= 1 Stop Loss = 813.9
    Entered internal SetStopTarget() method at 4/11/2007 10:48:00 AM: Type=Stop FromEntrySignal='' Mode=Price Value=813.9 Currency=0 Simulated=False
    ER2 06-07 In Short,Bars = 6648
    ER2 06-07 In Short, Adjusted Stop to MA = 812.631384615384
    Entered internal SetStopTarget() method at 4/11/2007 10:51:00 AM: Type=Stop FromEntrySignal='' Mode=Price Value=812.631384615384 Currency=0 Simulated=False
    ER2 06-07 In Short,Adjusted Target to = 807.6
    Entered internal SetStopTarget() method at 4/11/2007 10:51:00 AM: Type=Target FromEntrySignal='' Mode=Price Value=807.6 Currency=0 Simulated=False
    Also #1

    Does Avgprice() refer to the current trade/position, or an avg for the whole day?
    ie, can I use it for basing a Break-Even stop on?


    Also #2

    .. would you have any suggestions as to why my High.ToString() and Close.ToString()[0] are returning single digits in the output window? I thought it might be format str related, but the same syntax works elsewhere


    Many thanks for putting up with my endless questions.

    Zol

    #2
    imported post

    Can you please PM me complete strategy?

    Also:
    - which instrument?
    - which timeframe?

    Thanks

    Comment


      #3
      imported post

      Also,

      #1 - Average price of open position

      #2 - Close.ToString()[0] should be Close[0].ToString()
      RayNinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by wzgy0920, Yesterday, 09:53 PM
      2 responses
      49 views
      0 likes
      Last Post wzgy0920  
      Started by Kensonprib, 04-28-2021, 10:11 AM
      5 responses
      191 views
      0 likes
      Last Post Hasadafa  
      Started by GussJ, 03-04-2020, 03:11 PM
      11 responses
      3,230 views
      0 likes
      Last Post xiinteractive  
      Started by andrewtrades, Today, 04:57 PM
      1 response
      14 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by chbruno, Today, 04:10 PM
      0 responses
      7 views
      0 likes
      Last Post chbruno
      by chbruno
       
      Working...
      X