How to set a stop loss at low or high of 2 previous Heikin Ashi

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

    Dear all,

    I’m trying to set a stop loss 2 pips under or 2 pips above the high at 2 prevoius bar of a Heikin Ashi.

    I found something on the forum but it was talking about normal candles and not HA. I tried to adapt it to HA but it is not working as expected.

    I want the stop loss NOT to change at next bars.

    Here’s the code of Heikin Ashi I use:

    xClose = (open+high+low+close)/4
    IF BarIndex=0 THEN
    xOpen = open
    xHigh = high
    xLow = low
    ELSE
    xOpen = (xOpen[1] + xClose[1])/2
    xHigh = Max(Max(high, xOpen), xClose)
    xLow = Min(Min(low, xOpen), xClose)
    ENDIF

     

    To enter long:

    IF all my conditions THEN
    BUY 1 SHARES AT MARKET
    xsll = xlow[3]
    SET TARGET pPROFIT x
    ENDIF

     

    to enter short:

    IF all my conditions THEN
    SELLSHORT 1 SHARES AT MARKET
    xSLS = xhigh[3]
    SET TARGET pPROFIT y
    ENDIF

     

    finally to set stop loss:

    IF longonmarket THEN
    SELL AT xsll-2*pipsize STOP
    endif
    
    IF ShortOnMarket THEN
    BUY AT xsls+2*pipsize STOP
    ENDIF

     

    Here what happen:

    1. When it has to close long position looks not bad even if it sometimes the exit from position it’s lower then xlow[3], so I do not understand if it sell as soon as the price reach xlow[3]+2pipsize or it waits the bar where it reaches it to close.
    2. When it has to close short position it opens a countrary long position, so I found myself with a opened long postion which I don’t need. Regarding point where it closes the short position the issue is as above at point 1.

    I really appreciate your help!

    Thank you all!

    #22839 quote
    NicolasNicolas
    Keymaster
    Legend

    To close short position, you have to use EXITSHORT instruction, not BUY which is already made to go long on market.

    #22877 quote
    NikitaNikita
    Participant
    New

    Thank you Nicolas

    that was it! i’ve done some other changes and now it’s working as it should!

    Thank you again!

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

How to set a stop loss at low or high of 2 previous Heikin Ashi


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Nikita @nikita Participant
Summary

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

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