Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trade below EMA based on PIN bar

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

    Trade below EMA based on PIN bar

    Hello:
    I would like to know how to place trade only when a PIN bar is formed blow EMA for short and long when a bullish pin bar is formed above EMA(0).
    I have a code where I check for Open and Close and High Low of PIN bar value is lower than EMA(0) to place a short trade on a berish pin bar but it seems still placing short trades when berish PIN bar is formed above EMA .
    I am checking values are correct in PRINT log and it should only do a short for berish pin bar below EMA value that is higher than PIN bar.

    Any suggestion or examples code would help.

    My PIN bar logic is working fine. see the image attached where this PIN bar is berish and above EMA in orange but placed trade while it should be ignored. EMA1 is the input capable variable that I pass from strategy edit screen like 9 ema or 21 ema or any value and that is used to draw on chart and use for EMA value.

    Click image for larger version  Name:	image.png Views:	0 Size:	10.2 KB ID:	1306359

    if (Close[0] > EMA1[0] && Open[0] > EMA1[0] && High[0] > EMA1[0] && Low[0] > EMA1[0])
    // {
    // ABOVE_EMA = true;
    // }

    // if (Close[0] < EMA1[0] && Open[0] < EMA1[0] && High[0] < EMA1[0] && Low[0] < EMA1[0])
    // {
    // BELOW_EMA = true;
    // }​​

    Thanks
    Last edited by mt7860; 06-06-2024, 11:29 AM.

    #2
    Hello mt7860,

    I am not sure what a Pin bar is but I can say that your conditions are only toggling the variables to true. If you mean to toggle them based on the condition you also need an else conditions.

    If you are using the strategy builder you would have to add a set before these two conditions and set both variables to false so that they are only toggled to true when the condition is true, otherwise false. If you are manually coding you can just reset them above those conditions.

    ABOVE_EMA = false;
    BELOW_EMA = false;
    if (Close[0] > EMA1[0] && Open[0] > EMA1[0] && High[0] > EMA1[0] && Low[0] > EMA1[0])
    {
    ABOVE_EMA = true;
    }

    if (Close[0] < EMA1[0] && Open[0] < EMA1[0] && High[0] < EMA1[0] && Low[0] < EMA1[0])
    {
    BELOW_EMA = true;
    }​​​

    Comment


      #3
      hello, berish PIN Bar is basically a berish hang man or berish hammer bar is in my image.
      yes I do set them as false at the top in variable section and then I check and if one of the condition is true, I set the other condition to false at the end for the new bar to be evaluated like previous bar from the beginning


      // Other internal programming condition Variables

      NEW_DAY = true;
      DAILY_PNL = 0;
      CONTINUE_TRADING = true;
      WITHIN_TIME_RANGE = true;
      WITHIN_PNL_LIMIT = true;

      ABOVE_EMA = false;
      BELOW_EMA = false;

      Bull_Pin_Bar = false;
      Bear_Pin_Bar = false;

      //logic for pin bar is here...in my code.

      if (NEW_DAY && CONTINUE_TRADING && Bear_Pin_Bar && TRADE_SHORT && BELOW_EMA)
      {
      Print(@" ========================== Entered Short on Bear Signal Bar ================================================== ==========");
      EnterShort(Convert.ToInt32(DefaultQuantity), @"Sell");
      Print(Time[0]);

      Bear_Pin_Bar = false;
      Bull_Pin_Bar = false;
      BELOW_EMA = false;
      }​​​


      see the result it is placing the trade even pin bar is higher than the EMA in orange colour , it should ignore this bar based on above logic. here trade is place based on PIN bar found just before that red arrow

      Click image for larger version  Name:	image.png Views:	0 Size:	9.7 KB ID:	1306386

      and here is the correct way the trade was placed based on same logic, trade short below EMA when PIN bar is found,

      Click image for larger version

Name:	image.png
Views:	177
Size:	5.8 KB
ID:	1306390​​
      Last edited by mt7860; 06-06-2024, 05:23 PM.

      Comment


        #4
        Hello mt7860,

        If what you made is not working you would have to use prints to see why that is happening. To know why the conditions are becoming true you can add a print that outputs the values that are used in the conditions, that will tell you why the condition was true.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        633 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        364 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        105 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        567 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        568 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X