IF LONGONMARKET THEN / IF SHORTONMAKRET THEN

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #5481 quote
    DavidDavid
    Participant
    Veteran

    I have an inconsistency in execution of code and am wondering if some could test and get the same results.

    IF LONGONMARKET THEN SET STOP pLOSS SET TARGET pPROFIT – Doesn’t work

    IF SHORTONMAKRET THEN SET STOP pLOSS SET TARGET pPROFIT – Does work

    Maybe someone can explain why there’s this inconsistency

     

    //***** EXAMPLE 1: LONGONMARKET *****
    
    //*****STOP pLOSS AND TARGET pPROFIT DON'T WORK****
    
    // Definition of code parameters
    DEFPARAM CumulateOrders = FALSE // Cumulating positions
    
    // Conditions to enter long positions
    indicator1 = close
    indicator2 = Average[20](totalPrice) //
    c1 = (indicator1 CROSSES OVER indicator2)
    
    IF c1 THEN
     BUY 1 CONTRACT AT MARKET
    ENDIF
    
    // Stops and targets
    
    IF LONGONMARKET THEN
     SET TARGET pPROFIT 45 //
     SET STOP pLOSS 40 //
    ENDIF

     

    //***** EXAMPLE 2: SHORTONMARKET *****
    
    //*****STOP pLOSS AND TARGET pPROFIT DON'T WORK****
    
    // Definition of code parameters
    DEFPARAM CumulateOrders = FALSE // Cumulating positions
    
    // Conditions to enter short positions
    indicator1 = close
    indicator2 = Average[20](totalPrice) //
    c1 = (indicator1 CROSSES OVER indicator2)
    
    IF c1 THEN
     SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    
    // Stops and targets
    
    IF SHORTONMARKET THEN
     SET TARGET pPROFIT 45 //
     SET STOP pLOSS 40 //
    ENDIF

     

    Thank you.

    #5485 quote
    NicolasNicolas
    Keymaster
    Legend

    Well, I got no idea right now why it doesn’t work. But this code should solve your issue :

    IF c1 THEN
     SELLSHORT 1 CONTRACT AT MARKET
     SET TARGET pPROFIT 45 //
     SET STOP pLOSS 40 //
    ENDIF

     

    Let me know if it’s alright now!

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

IF LONGONMARKET THEN / IF SHORTONMAKRET THEN


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
David @dwgfx Participant
Summary

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

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 04/16/2016
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...