How to close a trade automatically?

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #115012 quote
    Marcel van Vliet
    Participant
    Veteran

    Hi Team, I wonder if it is possible to close a trade automatically at a certain time, or after a certain time when the trade is openend after price hitting a stop order or is manualy opened?

    If this is posible, can somebody teach me where to find this ordertype or how to code this?

    Thank you

    #115013 quote
    Vonasi
    Moderator
    Master

    It is not possible to mix manual and auto trading. If a position is opened in an auto strategy then you can either close it manually or automatically. If a trade is opened manually then you can only close it manually.

    If you want to open a trade in an auto strategy you can then check if price has dropped to or below a stop level and then set a flag so that you know it has done this. You can record the barindex or time when this occurs and then you then just need to count how much time has passed and/or check if a certain time is achieved and that the flag is set and then close the trade and reset the flag.

    Something like this (not tested):

    if (your long conditions) then
    buy 1 contract at market
    stopprice = close - 100 //set initial stop level
    endif
    
    if onmarket and not flag 
    stopprice = positionprice - 100 //set more accurate stop level
    if low < stopprice then //stop level hit
    flag = 1
    myindex = barindex //record bar that stop hit
    endif
    
    if flag and barindex = myindex + 24 then
    sell at market
    flag = 0 //reset flag
    endif
    
    #115014 quote
    robertogozzi
    Moderator
    Master

    It is not possible fdor ProOrder to close trades opened/modified manually.

    You can certainly close automatic trades opened at anytime, after N bars or at a specif TIME (and DATE, eventually) or when a price is hit.

    Since all strategies are executed when a bar closes, you may need to use the MTF support to use a lower TF to be more accurate.

    If your strategy runs on a 4-hour or Daily TF you can use a 1-minute TF to close/update that trade.

    edit: Vonasi is superfast!!!

    #115015 quote
    Vonasi
    Moderator
    Master

    edit: Vonasi is superfast!!!

    Marcel had to wait 44 minutes for my reply and 59 minutes for yours – I think we both need to up our game!

    Marcel van Vliet thanked this post
    #117289 quote
    Jack
    Participant
    Junior

    Hello,

    Can we do  a stop loss or take profit on a portion of a position with the new prorelatime V11  ? (partial position closing)

    Thanks

    Jack

    #117292 quote
    Vonasi
    Moderator
    Master

    Can we do  a stop loss or take profit on a portion of a position with the new prorelatime V11  ? (partial position closing)

    Whether we can do this in live automatic trading or not is purely the decision of the broker.  IG do not allow partial position closing at the moment and so we will all just have to wait until if and when they decide to allow it. The PRT platform is able to function already with partial position closing in back tests but if we put any strategy live it is not allowed as we are then trading both demo and live using the brokers server which does not allow it.

    #117302 quote
    GraHal
    Participant
    Master

    wait until if and when they (IG) decide to allow it.

    Seems daft / not logical (not allowing) as we can do partial closures when manual trading with IG.

    #117364 quote
    Jack
    Participant
    Junior

    What about with Interactive Brokers account + PRT ? are partial closing possible ?

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

How to close a trade automatically?


Platform Support: Charts, Data & Broker Setup

New Reply
Author
Summary

This topic contains 7 replies,
has 5 voices, and was last updated by Jack
6 years, 1 month ago.

Topic Details
Forum: Platform Support: Charts, Data & Broker Setup
Language: English
Started: 12/16/2019
Status: Active
Attachments: No files
Logo Logo
Loading...