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 ftsc2022, 10-25-2022, 12:03 PM
      5 responses
      255 views
      0 likes
      Last Post KeyonMatthews  
      Started by ScottW, Today, 06:09 PM
      0 responses
      3 views
      0 likes
      Last Post ScottW
      by ScottW
       
      Started by Board game geek, 10-29-2023, 12:00 PM
      14 responses
      244 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by Waxavi, 04-19-2024, 02:10 AM
      4 responses
      56 views
      0 likes
      Last Post sonia0101  
      Started by cmtjoancolmenero, Today, 03:58 PM
      0 responses
      9 views
      0 likes
      Last Post cmtjoancolmenero  
      Working...
      X