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

Pin Bar Indicator

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

    Pin Bar Indicator

    Looking for a pin bar indicator or someone who would be willing to convert the following to Ninja code. Thanks

    #property indicator_chart_window
    #property indicator_buffers 3
    #property indicator_color1 Red
    #property indicator_color2 Blue
    #property indicator_color3 White
    //----
    extern bool Show_Alert = true;
    extern bool Display_Doji = true;
    extern int Ext_BodySize=20;
    extern bool Display_SpinningTop = true;

    //---- buffers
    double upArrow[];
    double downArrow[];
    double sideArrow[];
    string PatternText[5000];
    double Rem[];
    double barheight;
    double bodysize;
    double tmpcls;
    int PB_bear;
    int PB_bull;
    int PB_spin;
    //+------------------------------------------------------------------+
    //| Custom indicator initialization function |
    //+------------------------------------------------------------------+
    int init()
    {
    SetIndexStyle(0, DRAW_ARROW, 0, 2);
    SetIndexArrow(0, 116);
    SetIndexBuffer(0, downArrow);
    SetIndexLabel(0,Rem);
    SetIndexLabel(1,Rem);
    SetIndexLabel(2,Rem);
    //----
    SetIndexStyle(1, DRAW_ARROW, 0, 2);
    SetIndexArrow(1, 116);
    SetIndexBuffer(1, upArrow);


    SetIndexStyle(2, DRAW_ARROW, 0, 2);
    SetIndexArrow(2, 116);
    SetIndexBuffer(2, sideArrow);

    return(0);
    }
    //+------------------------------------------------------------------+
    //| Custom indicator deinitialization function |
    //+------------------------------------------------------------------+
    int deinit()
    {
    ObjectsDeleteAll(0, OBJ_TEXT);
    return(0);
    }
    //+------------------------------------------------------------------+
    //| Custom indicator iteration function |
    //+------------------------------------------------------------------+
    int start()
    {
    double Range, AvgRange;
    int counter, setalert;
    static datetime prevtime = 0;
    int shift;
    int shift1;
    int shift2;
    int shift3;
    string pattern, period;
    int setPattern = 0;
    int alert = 0;
    int arrowShift;
    int textShift;
    double O, O1, O2, C, C1, C2, L, L1, L2, H, H1, H2;
    //----
    if(prevtime == Time[0])
    {
    return(0);
    }
    prevtime = Time[0];
    //----
    switch(Period())
    {
    case 1: period = "M1"; break;
    case 5: period = "M5"; break;
    case 15: period = "M15"; break;
    case 30: period = "M30"; break;
    case 60: period = "H1"; break;
    case 240: period = "H4"; break;
    case 1440: period = "D1"; break;
    case 10080: period = "W1"; break;
    case 43200: period = "MN"; break;
    }
    //----
    for(int j = 0; j < Bars; j++)
    {
    PatternText[j] = "pattern-" + j;
    }
    //----
    for(shift = 0; shift < Bars; shift++)
    {
    setalert = 0;
    counter = shift;
    Range = 0;
    AvgRange = 0;
    for(counter = shift; counter <= shift + 9; counter++)
    {
    AvgRange = AvgRange + MathAbs(High[counter] - Low[counter]);
    }
    Range = AvgRange / 10;
    shift1 = shift + 1;
    shift2 = shift + 2;
    shift3 = shift + 3;
    O = Open[shift1];
    O1 = Open[shift2];
    O2 = Open[shift3];
    H = High[shift1];
    H1 = High[shift2];
    H2 = High[shift3];
    L = Low[shift1];
    L1 = Low[shift2];
    L2 = Low[shift3];
    C = Close[shift1];
    C1 = Close[shift2];
    C2 = Close[shift3];
    // Bearish Patterns
    // Check for Bearish Engulfing pattern
    barheight=High[shift] - Low[shift];
    bodysize=0;
    PB_bear=0;
    PB_bull=0;
    PB_spin=1;

    if (Close[shift] >= Open[shift])
    {bodysize=Close[shift]-Open[shift];
    }
    if(Close[shift] < Open[shift])
    {bodysize=Open[shift]-Close[shift];
    }

    //Bullish tests: close OR high of body braches top quarter of Bar

    if (MathMax(Close[shift],Open[shift]) >= (High[shift] - (barheight/4)))
    {PB_bull=1; PB_spin=0;}

    if (MathMin(Close[shift],Open[shift]) <= (Low[shift] + (barheight/4)))
    {PB_bear=1; PB_spin=0;}



    //Bearish Doji: small body closing in lower third of bar
    if((bodysize/barheight)<=(0.25) && (PB_bear==1))
    {
    if(Display_Doji == true)
    {
    ObjectCreate(PatternText[shift], OBJ_TEXT, 0, Time[shift],
    High[shift] + Range*1.5);
    ObjectSetText(PatternText[shift], " ", 10,
    "Times New Roman", Red);

    downArrow[shift] = High[shift] + Range*0.3;

    }
    if(setalert == 0 && Show_Alert == true)
    {
    pattern = "PinBar: Bullish";
    setalert = 1;
    }
    }

    //Bulliish Doji: small body closing in top third of bar
    if((bodysize/barheight)<=(0.25) && (PB_bull==1))
    {
    if(Display_Doji == true)
    {
    ObjectCreate(PatternText[shift], OBJ_TEXT, 0, Time[shift],
    Low[shift] - Range*1.5);
    ObjectSetText(PatternText[shift], " ", 10,
    "Times New Roman", Blue);

    upArrow[shift] = Low[shift] - Range*0.3;

    }
    if(setalert == 0 && Show_Alert == true)
    {
    pattern = "PinBar: Bearish";
    setalert = 1;
    }
    }

    //Spinning Top Doji: small body closing in middle of bar
    if((bodysize/barheight)<=(0.25) && (PB_spin==1))
    {
    if(Display_Doji == true)
    {
    ObjectCreate(PatternText[shift], OBJ_TEXT, 0, Time[shift],
    High[shift] + Range*1.5);
    ObjectSetText(PatternText[shift], " ", 10,
    "Times New Roman", White);

    sideArrow[shift] = High[shift] + Range*0.3;

    }
    if(setalert == 0 && Show_Alert == true)
    {
    pattern = "PinBar: SpinTop";
    setalert = 1;
    }
    }


    // Check for a Three Outside Down pattern

    // Check for a Dark Cloud Cover pattern

    // Check for Evening Doji Star pattern

    // Check for Bearish Harami pattern

    // Check for Three Inside Down pattern

    // Check for Three Black Crows pattern

    //Check for Evening Star Pattern

    // End of Bearish Patterns
    // Bullish Patterns
    // Check for Bullish Engulfing pattern

    // Check for Three Outside Up pattern

    // Check for Bullish Harami pattern

    // Check for Three Inside Up pattern

    // Check for Piercing Line pattern

    // Check for Three White Soldiers pattern

    // Check for Morning Doji Star

    if(setalert == 1 && shift == 0)
    {
    Alert(Symbol(), " ", period, " ", pattern);
    setalert = 0;
    }
    } // End of for loop
    return(0);
    }
    //+------------------------------------------------------------------+

    #2
    Thanks for posting the code, hopefully someone from the community can help you out.

    For a professional conversion, you can always contact those NinjaScript consultants - http://www.ninjatrader.com/webnew/pa...injaScript.htm
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Hi jrobin,

      I had a go at creating a pinbar indicator. I have put in an extra 2 different time frames including the existing chart time frame. I have used a Doji style pinbar as opposed to a larger body, however you can define a support resistance brakeout under barcount. I would like to get some feed back from you (considering you know what you are looking for) so that I can make it better and happy to activate it for you for free if you are interested.
      I am considering having the doji styla as optional except it seems to be more powerfull with it on lower level time frames and stops getting markers all over the shop.



      Thanks raef

      Comment


        #4
        Pin Bar Update

        Hi Guys,

        I have Updated the Pin Bar Indicator free to those that already own it.

        I have included the option to use with the strategy wizard for strategy back testing or market analyser. Can be found here



        Happy piping Raef.
        Attached Files

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by algospoke, Yesterday, 06:40 PM
        2 responses
        19 views
        0 likes
        Last Post algospoke  
        Started by ghoul, Today, 06:02 PM
        3 responses
        14 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by jeronymite, 04-12-2024, 04:26 PM
        3 responses
        45 views
        0 likes
        Last Post jeronymite  
        Started by Barry Milan, Yesterday, 10:35 PM
        7 responses
        21 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by AttiM, 02-14-2024, 05:20 PM
        10 responses
        181 views
        0 likes
        Last Post jeronymite  
        Working...
        X