Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Logic is broken

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

    Logic is broken

    HI i have a logic where I want to enter short limit order to go short one tick below flagEntryLevel.
    trendlineValueUp is evaluating correctly and prints Current trendline Up value at bar 0: 19553, I then assign flagEntryLevel to trendlineValueUp
    However nothing else gets printed even when bar closes below trendline. I dont know what is going on.
    Any help would be appriciated. Strategy is on bar close.

    if(trendDirection == cFalling
    // && stochPrim[0] < 50
    )
    {
    bool isLowSequence = true;
    for (int i = 0
    ; i < lookbackPeriod; i++)
    {
    if (Low[i] <= Low[i + 1])
    {
    isLowSequence = false;
    break;
    }
    }

    if (isLowSequence && doOnce==false)
    {
    double slope = (Low[0] - Low[lookbackPeriod]) / lookbackPeriod;
    trendlineValueUp = Low[0] - (slope * 0);
    Draw.Line(this, "BearFlag" + CurrentBar, true, lookbackPeriod, Low[lookbackPeriod], 0, Low[0], Brushes.Aqua, DashStyleHelper.Solid, 2);
    bearFlag = true;
    Print("Current trendline Up value at bar 0: " + trendlineValueUp);
    Alert("Alert", Priority.High, "Up trend line broken", NinjaTrader.Core.Globals.InstallDir+@"\sounds\Reve rsing.wav", 10, Brushes.Transparent, Brushes.Transparent);
    // PlaySound(@"C:\Program Files (x86)\NinjaTrader 8\sounds\VolumeSpike.wav");
    doOnce=true;
    }
    else
    {
    bearFlag = false;
    }
    if(bearFlag)
    {
    Print("bear flag is true today");
    Print("Close0"+Close[0]);
    Print("trendlineValueUp"+trendlineValueUp);
    bearFlagEntry = true;
    flagEntryLevel = trendlineValueUp - TickSize;
    Print("Time:"+Time[0]);
    Print("flagEntryLevel"+flagEntryLevel);
    Print("Close[0]"+Close[0]);
    }
    // We don't reset bearFlagEntry immediately, so that the entry condition can still evaluate
    if (bearFlagEntry)
    {
    // Evaluate if Close[0] is below the flag entry level
    if (Close[0] < flagEntryLevel)
    {
    Print("jambo");
    // EnterShort(0, PositionSize, "LB Short");
    EnterShortStopMarket(0,true, PositionSize, flagEntryLevel,"MyEntryShort");
    // Reset bearFlagEntry only after the trade is executed
    bearFlagEntry = false;
    }
    }

    }​
    Last edited by tkaboris; 09-09-2024, 02:44 PM.

    #2
    Hello tkaboris,

    From the given code I don't see anything that specifically looks wrong. Which specific print is not happening?

    Comment


      #3
      HI i was able to fix it with this code. HOwever, how can I make sure that trade is executed using
      bullFlagEntryLevel only once. Currently I have trade executed and later on it may take a trade again because condition around bullFlagEntryLevel is true.... How to do that?



      if(BullBearFlag && trendDirection == 1
      // && stochPrim[0] > 70
      )
      {
      bool isHighSequence = true;
      for (int i = 0; i < lookbackPeriod - 1; i++)
      {
      if (High[i] >= High[i + 1])
      {
      isHighSequence = false;
      break;
      }
      }
      if (isHighSequence)
      {
      double slope = (High[lookbackPeriod -1] - High[0]) / lookbackPeriod;
      trendlineValueDn = (slope * (0) + High[0]);

      Draw.Line(this, "BullFlag" + CurrentBar, true, lookbackPeriod, High[lookbackPeriod -1], 0, High[0], Brushes.Red, DashStyleHelper.Solid, 2);
      bullFlag = true;
      Print("Current trendline Down value at bar 0: " + trendlineValueDn);
      Alert("Alert", Priority.High, "Up trend line broken", NinjaTrader.Core.Globals.InstallDir+@"\sounds\Reve rsing.wav", 10, Brushes.Transparent, Brushes.Transparent);


      }
      if(bullFlag && isHighSequence)//&& Low[0] <= trendlineValueDn && Close[0] > trendlineValueDn
      {
      bullFlagEntryLevel = trendlineValueDn + TickSize;
      bullFlagEntry = true;
      Print("bullflag in bullFlagEntryLevel"+ Time[0]);
      }
      if(bullFlag && !isHighSequence && ((trendDirection == -1) || (Close[0] > bullFlagEntryLevel)))
      {
      bullFlag = false;
      }
      else if (!isHighSequence && !(Low[0] <= trendlineValueDn && Close[0] < trendlineValueDn) )
      {
      bullFlag = false;
      bullFlagEntry = false;
      Print("bullflag false"+ Time[0]);
      }

      }​

      if(beforeTradeLongCheck && bullFlagEntry && Close[0] < bullFlagEntryLevel)
      {
      // EnterLong(0,PositionSize, "LB Long");
      EnterLongStopMarket(0,true, PositionSize, bullFlagEntryLevel, "LB Long");
      bullFlagEntry = false;
      }​

      Comment


        #4
        Hello tkaboris,

        That depends on how your logic surrounding that bool variable works. To have the condition not work again you would have to toggle the bool value to the opposite of what makes the condition true. Where you toggle the bool depends on how you intend your logic to work, I can't really provide a specific suggestion for that part.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        79 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        40 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        63 views
        2 likes
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        63 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        54 views
        0 likes
        Last Post CarlTrading  
        Working...
        X