target profit moving average

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #213059 quote
    8278sv
    Participant
    New

    Hi,

    I was hoping someone could shed some light as still learning the coding on here. If i I wanted to set a target of the price touching the moving average line, how would I code this?

     

    Thank you

    #213060 quote
    JS
    Participant
    Senior

    Hi,

    S1 = Average[Period](Close)
    
    Set Target Price S1
    8278sv thanked this post
    #213175 quote
    8278sv
    Participant
    New

    Just a follow up question; how do I do partial closure?

    For example two different close positions based on two different moving averages. I have the below code but not sure how to add that

    1*atr closes when it reaches 50 moving average

    and then the remaining (1*atr) closes when price touches 100 moving average

    also, if i wanted to bring the stop loss up to breakeven when it touches for example the 50 moving average, how could i code this?

    Any help would be much much appreciated

    atr= averagetruerange[12](close)
    ma1=average[50]
    ma2=average[100]
    
    IF Bullish0 THEN
    buy (200/(2*atr)) perpoint AT MARKET
    set stop loss (2*atr)
    set target price (ma1)
    ENDIF
    
    #213182 quote
    ZeroCafeine
    Participant
    Senior

    for Breakeven you can maybe look at this page it will help you, and about selling at 2 level

    for selling at 2 level of price maybe you can use 2 IF condition and Sell 1 shares when the condition it met

    #213184 quote
    Nicolas
    Keymaster
    Master

    to close partially an order, nice example from Roberto: https://www.prorealcode.com/topic/replacing-tp-with-partial-close/#post-194694

    to put order at breakeven (and many other possibilites) with these new instructions: New trading instructions: better management of your orders!

    #216237 quote
    8278sv
    Participant
    New

    Hi, just wanted to follow up – based on the above formula – with targeting the moving average as a target price, it seems to execute at the moving average value directly correlating with opening candle of the trade. Is it possible to have the target price move with the moving average so its dynamic. So if the todays candle price touches the moving average it closes at that point. With the formula above, it doesnt seem to close, only when the price hits the initial moving average value that was calculated when the trade first opened. Its a bit difficult to explain – hope this makes sense.

    #216241 quote
    robertogozzi
    Moderator
    Master

    Swap lines 8 and 9, so that set target price (ma1) is the last line, i.e. outside the conditionl block IF…ENDIF and will ALWAYS be executed, not just at entry time.

    Be warned that ma1 might be lower than the prior candle, thus exiting at a lower price than originally set.

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

target profit moving average


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
8278sv @8278sv Participant
Summary

This topic contains 6 replies,
has 5 voices, and was last updated by robertogozzi
2 years, 8 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 04/09/2023
Status: Active
Attachments: No files
Logo Logo
Loading...