Stop loss moving averages

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #213214 quote
    Ludde
    Participant
    New

    Hi. I need need help with a indicator. I have managed to make an indicator where a moving average cross over an other moving average.  If the shorter moving average is above the longer the indicater shovs 1  and if it is under it shows 0.

    If you trade on crossovers it could take a while if your stop loss is when the averages cross over each other  in the opposite direction. So I use a stopp loss in percent.

    Let say that you want to go long when the short moving average cross over the long average.  Then I want an indicater that shows 1 when the loss is 0.2 percent or more. Otherwise it shows 0.

    So from the closing price when the short average cross over the long I want the indicator to show 1 as soon as the indicater show a loss of 0.2 percent or more.

    I also want an other indicator that shows the opposite if I go short when the shorter average goes below the longer average.

    It would be good if i push on configure i could choose between diffrent averages like exponential moving average and other sorts of averages. And you could choose betwen the length of the short and long average. You should also be able to choose how much loss you can accept in percent.

    I would be very happy i some one could help me make such an indicator.

    #213226 quote
    JS
    Participant
    Senior

    Hi,

    Maybe this is a start…

     

    Once FastPeriod=20 //Fast Period
    Once SlowPeriod=40 //Slow Period
    Once FastMAType=1 //EMA
    Once SlowMAType=4 //Triangular MA
    Once PercMaxLoss=0.2 //Max Percentage Loss
    
    FastMA=Average[FastPeriod,FastMAType](Close)
    SlowMA=Average[SlowPeriod,SlowMAType](Close)
    
    If FastMA Crosses Over SlowMA then
    Long=1
    Short=0
    CrossPriceLong=Close
    EndIf
    
    If Long=1 and(Close/CrossPriceLong - 1)*100<= -PercMaxLoss then
    LongSignalPerc=1
    Else
    LongSignalPerc=0
    EndIf
    
    If FastMA Crosses Under SlowMA then
    Long=0
    Short=1
    CrossPriceShort=Close
    EndIf
    
    If Short=1 and (1 - Close/CrossPriceShort)*100<= -PercMaxLoss then
    ShortSignalPerc=1
    Else
    ShortSignalPerc=0
    EndIf
    
    Return LongSignalPerc as "LongSignalPerc", ShortSignalPerc as "ShortSignalPerc"
    
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

Stop loss moving averages


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Ludde @ludde Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by JS
2 years, 10 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 04/12/2023
Status: Active
Attachments: 1 files
Logo Logo
Loading...