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

Consecutive closes above or below moving average

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

    Consecutive closes above or below moving average

    Hi All.

    I'm looking for the most efficient way to code the following condition.

    1. Look for the first x number of closes above a moving average - print an arrow/bar colour etc - ignore all subsequent signals
    1.1 Signal can re-activate if price comes back to the ma (touches or closes below) and then x number of closes above - print arrow - ignore all subsequent signals
    2. Reverse of the above conditions for closes below

    If entry/pt/sl lines can be drawn above/below setup bar that would be ideal - these would be variables. i.e 2tick for entry, 16tick for sl and pt1/pt2/pt3

    The Tradingview code is below:


    -----------------------
    study("Indicator_ConsecutiveLH_SMA", overlay=true)

    //this is a very simple indicator that marks a candle if it has consecutive closes above or below the SMA

    sma_period = input(5,title="SMA length") //configure the SMA
    consecutive_lowhighmin = input(5,title="Consecutive LH Minimum") //configure the consecutive Low or High on one side of the SMA to trigger a trade
    consecutive_lowhighmax = input(6,title="Consecutive LH Maximum") //if there are too many consecutive Low or High we will not trade

    //key SMA
    keySMA = sma(close,sma_period)

    consecutiveBarsAbove = barssince(low<keySMA)
    consecutiveBarsBelow = barssince(high>keySMA)

    BullCloseAboveMinConsecutive = consecutiveBarsAbove >= consecutive_lowhighmin
    BullCloseBelowMaxConsecutive = consecutiveBarsAbove < consecutive_lowhighmax

    BearCloseAboveMinConsecutive = consecutiveBarsBelow >= consecutive_lowhighmin
    BearCloseBelowMaxConsecutive = consecutiveBarsBelow < consecutive_lowhighmax

    BullCloseIndicator = BullCloseAboveMinConsecutive and BullCloseBelowMaxConsecutive //consective closes between the min and max values
    BearCloseIndicator = BearCloseAboveMinConsecutive and BearCloseBelowMaxConsecutive

    barcolor(BullCloseIndicator ? color.yellow : BearCloseIndicator ? color.yellow : na)
    //barcolor(BearCloseIndicator ? color.yellow : color.green)
    //plotchar(BullCloseIndicator,title="BullIndicator", char="U",color=blue,size=size.tiny,location=locati on.abovebar)
    //plotchar(BearCloseIndicator,title="BearIndicator", char="D",color=red,size=size.tiny,location=locatio n.belowbar)



    Many thanks,
    Bernie

    #2
    Hello traderslab,

    Thanks for your post and welcome to the NinjaTrader forums!

    Please note that NinjaTrader does not provide coding or debugging services and we can leave this thread open for anyone that would like to create this for you.

    Another alternative is if you would like this created for you, we can provide a link to 3rd party programmers in the NinjaTrader ecosystem.

    If you would like to take on creating this yourself, we can provide you with links to get you started with Ninjascript.
    Paul H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Brevo, Today, 01:45 AM
    0 responses
    3 views
    0 likes
    Last Post Brevo
    by Brevo
     
    Started by aussugardefender, Today, 01:07 AM
    0 responses
    3 views
    0 likes
    Last Post aussugardefender  
    Started by pvincent, 06-23-2022, 12:53 PM
    14 responses
    239 views
    0 likes
    Last Post Nyman
    by Nyman
     
    Started by TraderG23, 12-08-2023, 07:56 AM
    9 responses
    384 views
    1 like
    Last Post Gavini
    by Gavini
     
    Started by oviejo, Today, 12:28 AM
    0 responses
    6 views
    0 likes
    Last Post oviejo
    by oviejo
     
    Working...
    X