Setting a pending order while on market

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #25540 quote
    kg6450
    Participant
    Average

    Hi all, I was scrolling through other forums looking for ideas and I came across one that looks interesting.

    The link is here if anyone’s interested and the premise is to enter on the 9th bar (hour) of the day based on a certain pattern with a 10 point target and stop. If the stop is hit, a pending order is placed of twice the size 5 points away for reentry in the opposite direction.

    The code I have so far is:

    DEFPARAM CumulateOrders = False
    
    //Buy patterns
    Buy1 = (Close[2] > Open[2]) AND (Close[1] > Open[1]) AND (Close > Open)
    Buy2 = (Close[2] > Open[2]) AND (Close[1] < Open[1]) AND (Close > Open)
    Buy3 = (Close[2] > Open[2]) AND (Close[1] > Open[1]) AND (Close < Open)
    Buy4 = (Close[2] < Open[2]) AND (Close[1] > Open[1]) AND (Close > Open)
    
    //Sell patterns
    Sell1 = (Close[2] < Open[2]) AND (Close[1] < Open[1]) AND (Close < Open)
    Sell2 = (Close[2] < Open[2]) AND (Close[1] > Open[1]) AND (Close < Open)
    Sell3 = (Close[2] < Open[2]) AND (Close[1] < Open[1]) AND (Close > Open)
    Sell4 = (Close[2] > Open[2]) AND (Close[1] < Open[1]) AND (Close < Open)
    
    //Check pattern at 9th bar of the day
    Check = (INTRADAYBARINDEX = 8)
    
    IF Check THEN
    IF Buy1 OR Buy2 OR Buy3 OR Buy4 THEN
    Buy 1 SHARES AT MARKET
    ELSIF Sell1 OR Sell2 OR Sell3 OR Sell4 THEN
    SELL 1 SHARES AT MARKET
    ENDIF
    ENDIF
    
    SET TARGET pPROFIT 10
    SET STOP pLOSS 10
    

    What I’m struggling to set at the moment is the pending orders part, Does anyone know a way to set it?

    #25577 quote
    Nicolas
    Keymaster
    Master

    So you have already coded the first part of the strategy? right?
    and now you are stuck here? :

    If the stop is hit, a pending order is placed of twice the size 5 points away for reentry in the opposite direction.

    #25632 quote
    kg6450
    Participant
    Average

    Hi Nicholas,

    Yes the code I posted was the basic coding of the patterns (the bullish and bearish candles). The part that I’m struggling with is the setting of the pending order for the opposite direction if the stop is it

    #25638 quote
    Nicolas
    Keymaster
    Master

    So there is only 2 trades possible each day? The first one at intradaybarindex=8 and the “recovery” one which is a pending order?

    What do you mean by ” twice the size 5 points away ” ?

    #25657 quote
    kg6450
    Participant
    Average

    Yeah that’s right, on the 8th bar, it will take a position depending based on what pattern formed. It will also set a pending order 5 points away from the stop loss level.

    Sorry, by that I meant twice the size of the original position; so after the 8th bar we enter at £1 per point, and the pending order is set at £2 per point.

    I’m sorry if I’m explaining it badly!

    #25881 quote
    Nicolas
    Keymaster
    Master

    Ok good, this code attempt should be tested (forum coding):

    DEFPARAM CumulateOrders = False
    
    if intradaybarindex=0 then 
     count=0
    endif
    
    //Buy patterns
    Buy1 = (Close[2] > Open[2]) AND (Close[1] > Open[1]) AND (Close > Open)
    Buy2 = (Close[2] > Open[2]) AND (Close[1] < Open[1]) AND (Close > Open)
    Buy3 = (Close[2] > Open[2]) AND (Close[1] > Open[1]) AND (Close < Open)
    Buy4 = (Close[2] < Open[2]) AND (Close[1] > Open[1]) AND (Close > Open)
    
    //Sell patterns
    Sell1 = (Close[2] < Open[2]) AND (Close[1] < Open[1]) AND (Close < Open)
    Sell2 = (Close[2] < Open[2]) AND (Close[1] > Open[1]) AND (Close < Open)
    Sell3 = (Close[2] < Open[2]) AND (Close[1] < Open[1]) AND (Close > Open)
    Sell4 = (Close[2] > Open[2]) AND (Close[1] < Open[1]) AND (Close < Open)
    
    //Check pattern at 9th bar of the day
    Check = (INTRADAYBARINDEX = 8)
    
    IF Check and count=0 THEN
     IF Buy1 OR Buy2 OR Buy3 OR Buy4 THEN
      Buy 1 SHARES AT MARKET
      count=count+1
      direction = 1
     ELSIF Sell1 OR Sell2 OR Sell3 OR Sell4 THEN
      SELLSHORT 1 SHARES AT MARKET
      count=count+1
      direction = -1 
    ENDIF
    ENDIF
    
    //recovery trade
    if count=1 and positionperf(1)<0 then 
     if direction>0 then 
      sellshort 2 shares at positionprice-15*pointsize stop 
     endif
     if direction<0 then 
      buy 2 shares at positionprice+15*pointsize stop
     endif
     if onmarket then 
      count=count+1
     endif
    endif
    
    SET TARGET pPROFIT 10
    SET STOP pLOSS 10
    #25976 quote
    kg6450
    Participant
    Average

    Thanks Nicholas, I’ll test it and run it on demo for a while and let you know how it goes!

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

Setting a pending order while on market


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
kg6450 @kg6450 Participant
Summary

This topic contains 6 replies,
has 2 voices, and was last updated by kg6450
9 years ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 02/18/2017
Status: Active
Attachments: No files
Logo Logo
Loading...