Please help me complete this code

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #194483 quote
    Lucky1Lucky1
    Participant
    New

    My objective is to initiate a signal when close is less than an EMA for a certain number of bars.

    I have never used FOR/WHILE loops before and need help resetting my counter when a trade is initiated. So far, I can only get it to reach the counter once, enter a trade then every time it closes a trade it will immediately re-open a trade as the counter has not reset.

    Thank you for your help everyone.

    i = 0
    ema1 = exponentialaverage[500](close)
    if not onmarket then
    orig = 0 
    endif
    
    while close<ema1 and i<11 do
    i = i+1
    
    if i>10 then
    buysignal = 1
    endif
    wend
    
    
    if not longonmarket and buysignal = 1 then
    buy 1 contract at market
    if orig = 0 then
    orig = close
    if i <>0 then
    i = 0
    endif
    endif
    else
    
    if longonmarket and close>orig*1.02 then
    sell at market
    if i <>0 then
    i = 0
    endif
    else
    if longonmarket and close<orig*0.98 then
    sell at market
    if i <>0 then
    i = 0
    endif
    endif
    endif
    endif
    
    
    #194493 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Try replacing lines 7-13 (and you can remove line 1) with these:

     If (summation[11](close<ema1) = 11) then
       buysignal = 1
    Endif
    #194494 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    If you still want to use the WHILE iteration, change line 7 this way:

    while close[i]<ema1[i] and i<11 do
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

Please help me complete this code


General Trading: Market Analysis & Manual Trading

New Reply
Author
author-avatar
Lucky1 @lucky1 Participant
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by robertogozzirobertogozzi
4 years, 3 months ago.

Topic Details
Forum: General Trading: Market Analysis & Manual Trading
Language: English
Started: 06/02/2022
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...