Setting Stop Loss to EMA at Entry

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #171997 quote
    MishapMishap
    Participant
    Junior

    Hi Guys,

    Not sure how to word this so here goes.

    I want to set stop loss & take profit based on low of 2 candles ago. the stop loss is to use an EMA as the stop ie: if low[2] is below EMA[20] the stop loss is to be at EMA[50].

    further to this i would like to set take profit at 1.5* the stop loss.

    Apologies if this has been covered before i searched the forums but could not find a suitable solution.

    I have also had no luck trying to code this myself & have just failed miserably. any help is appreciated šŸ™‚

    cheers

    #171999 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    There you go:

    Ema20 = average[20,1](close)
    Ema50 = average[50,1](close)
    IF low[2] < Ema20 THEN
      SL = abs(close - Ema50)   //Stop Loss set to the difference between current price and Ema50
      TP = SL * 1.5
      SET STOP   LOSS   SL
      SET TARGET PROFIT TP
    ENDIF
    Mishap and Nicolas thanked this post
    #172005 quote
    MishapMishap
    Participant
    Junior

    Thanks mate, legend!

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

Setting Stop Loss to EMA at Entry


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Mishap @mishap Participant
Summary

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

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 06/18/2021
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...