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 lightsun47, Today, 03:51 PM
    0 responses
    4 views
    0 likes
    Last Post lightsun47  
    Started by 00nevest, Today, 02:27 PM
    1 response
    8 views
    0 likes
    Last Post 00nevest  
    Started by futtrader, 04-21-2024, 01:50 AM
    4 responses
    44 views
    0 likes
    Last Post futtrader  
    Started by Option Whisperer, Today, 09:55 AM
    1 response
    13 views
    0 likes
    Last Post bltdavid  
    Started by port119, Today, 02:43 PM
    0 responses
    9 views
    0 likes
    Last Post port119
    by port119
     
    Working...
    X