Stop loss only during set trading hours

Viewing 2 posts - 16 through 17 (of 17 total)
  • Author
    Posts
  • #202860 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Try this one:

    N  = 100
    sl = 100 * pipsize
    tp = 400 * pipsize
    OK = time >= 100000 AND time <= 170000
    if OK and not onmarket and close crosses over average[N,0](close) then
       buy at market
       exitprice = close - sl
    endif
    if OK and not onmarket and close crosses under average[N,0](close) then
       sellshort at market
       exitprice = close + sl
    endif
    IF OK then
       set target profit tp
    ELSE
       set target profit 0
    endif
    set stop   loss   0
    if OK then
       if longonmarket then
          if close > exitprice then
             sell at exitprice STOP
          elsif close < exitprice then
             sell at exitprice LIMIT
          endif
       elsif shortonmarket then
          if close > exitprice then
             exitshort at exitprice LIMIT
          elsif close < exitprice then
             exitshort at exitprice STOP
          endif
       endif
    endif
    //graph positionprice * positionperf / pipsize as "tempGain"
    graph OK > 0
    graphonprice tradeprice                      as "Entry price"
    graphonprice exitprice coloured(255,0,0,255) as "Stop Loss"
    #202974 quote
    ProRealPProRealP
    Participant
    Senior

    Thanks!

    I’ll give it a go and see how it works out.

Viewing 2 posts - 16 through 17 (of 17 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

Stop loss only during set trading hours


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
ProRealP @prorealpierre Participant
Summary

This topic contains 16 replies,
has 5 voices, and was last updated by ProRealPProRealP
4 years ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 08/13/2022
Status: Active
Attachments: 2 files
ProRealCode ProRealCode
Loading...