Maximize profit based on the price move

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #182979 quote
    Amin1233
    Participant
    Junior

    Hi , Anyone can help with the below code please??

    the idea is to not exit a position if it is still going your way. So if longonmarket and it is in profit (+15 points) then update the target profit to 50 and only exit when the candle finishes lower than the previous candle.

    if longonmarket and  close[0]-positionprice>15 then
    set target profit 40
    if close[0]<lowest[1] then
    sell countofposition contracts at market
    endif
    endif

    Not sure what is wrong, but it only changes the target profit and the second condition doesnt work.

    #182986 quote
    robertogozzi
    Moderator
    Master

    Try this:

    if not OnMarket then
       flag = 0
    endif
    if longonmarket and  close[0]-positionprice>15 then
       set target profit 40
       flag = 1
    endif
    if close[0]<lowest[1] and flag then
       sell countofposition contracts at market
    endif
    #182994 quote
    murre87
    Participant
    Senior

    Intressting topic. An active TP need an active SL too.
    How do u manage SL in ur strategy Amin1233?

    #183006 quote
    Amin1233
    Participant
    Junior

    Hi Roberto. Still not working. I try to only add the second part to test and it just doesnt make any difference to the result which is impossible.

     

    if not OnMarket then
    flag = 0
    endif
    if longonmarket and close[0]-positionprice>15 then

    flag = 1
    endif
    if close[0]<lowest[1] and flag then
    sell countofposition contracts at market
    endif

    #183007 quote
    Amin1233
    Participant
    Junior

    Murre, I dont change the SL.In this strategy you wouldnt need Stop loss because when the price goes below the last bar it should exit.

    #183020 quote
    JC_Bywan
    Moderator
    Master

    Hi, “candle finishes lower than previous candle” is close[0]<low[1], not close[0]<lowest[1]

    robertogozzi thanked this post
    #183048 quote
    Amin1233
    Participant
    Junior

    thanks

    #184743 quote
    RichardVeen
    Participant
    Junior

    Hi,

    The code above is a great idea but it is not working for me.

    Below the code I testen and the target is not moving despite of the fact that the close(0) – positionprice > 5

    What is wrong with the code?

    //profit & loss
    SET TARGET PROFIT 40
    SET STOP pLOSS 20

    if not OnMarket then
    flag = 0
    endif
    if longonmarket and close[0]-positionprice>5 then
    set target profit 50
    flag = 1
    endif

    if close[0]<low[1] and flag then
    sell countofposition contracts at market
    endif

    #184755 quote
    JS
    Participant
    Senior

    Hi @RichardVeen

    Remove the “Set Target Profit 40” at the top of your code.

    (Otherwise it will reset every time to 40)

    #184766 quote
    RichardVeen
    Participant
    Junior

    Yes, you are right, it is working!

    Thanks!

    JS thanked this post
Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.

Maximize profit based on the price move


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Amin1233 @amin1233 Participant
Summary

This topic contains 9 replies,
has 6 voices, and was last updated by RichardVeen
4 years, 1 month ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 12/08/2021
Status: Active
Attachments: No files
Logo Logo
Loading...