Buy after N number of bars please help

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #34825 quote
    DAKDAK
    Participant
    Average

    Hi everyone,

    I would need some help for a little code.

    I am trying to code the following strategy :

    • Wait for EMA 5 AND EMA 10 to cross but don’t enter
    • After a certain number of bars, if EMA 5 is still above EMA 10 then you can enter the market

    The number of bars to wait is issued from a third indicator and this value is changing over time.

    I tried but didn’t manage to code properly this strategy. Any help would be very appreciated. If it really works I will publish it.

    Many thanks.

    
    // Indicators
    
    ind1 = ExponentialAverage[5](close)
    
    ind2 = ExponentialAverage[10](close)
    
    ind3 = customvalue
    
    // IF ind1 CROSSES OVER ind2 THEN BUY AFTER "customvalue" number of bars IF ind1 still > ind2
    #34844 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Try this one (I didn ‘t):

    DEFPARAM CumulateOrders       = False
    
    ONCE NumberOfBars             = 0                                               //Initial value
    
    IF OnMarket OR (ExponentialAverage[5] CROSSES UNDER ExponentialAverage[10]) THEN//Reset counter to ZERO
       NumberOfBars = 0                                                             //  while trade is open OR
    ENDIF                                                                           //  Ema's cross the other way round
    
    IF NumberOfBars THEN                                                            //If previously CROSSED, add
       NumberOfBars = NumberOfBars + 1                                              //  add 1 at each bar
    ENDIF
    
    IF ExponentialAverage[5] CROSSES OVER ExponentialAverage[10] THEN
       NumberOfBars = 1                                                             //Start counting after crossing up
    ENDIF
    
    IF NumberOfBars >= your_indicator_value THEN
       BUY 1 CONTRACTS AT MARKET
    ENDIF
    
    Nicolas thanked this post
    #34900 quote
    DAKDAK
    Participant
    Average

    Thanks very much it works like a charm !

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Buy after N number of bars please help


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
DAK @dak Participant
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by DAKDAK
9 years, 5 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 05/08/2017
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...