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 WHICKED, Yesterday, 11:12 PM
    0 responses
    5 views
    0 likes
    Last Post WHICKED
    by WHICKED
     
    Started by AdeptistJune, Yesterday, 08:08 PM
    1 response
    6 views
    0 likes
    Last Post bltdavid  
    Started by GKbowen, Yesterday, 04:03 PM
    3 responses
    12 views
    0 likes
    Last Post bltdavid  
    Started by bojim, Yesterday, 08:35 PM
    0 responses
    4 views
    0 likes
    Last Post bojim
    by bojim
     
    Started by jamestrader21x, Yesterday, 07:53 AM
    8 responses
    34 views
    0 likes
    Last Post NinjaTrader_Kate  
    Working...
    X