Auto Trading Help
Forums › ProRealTime English forum › ProOrder support › Auto Trading Help
- This topic has 6 replies, 3 voices, and was last updated 2 years ago by robertogozzi.
-
-
08/14/2021 at 1:24 AM #175266
Hi All
I am pretty new in coding. is it possible to automate trading with rules below? Also how much ProREaltime will charge for Auto Order?
Buy 80 Contract at market
Set Trailing Stop loss = Distance 25, Step = 20
If Market Price – Entry Price =20 then Close 40
If Market Price – Entry = 30 then Close 20
If Market Price – Entry = 40 then Close 10
If time = 2:00 pm or Entry time + 4 Hrs and nothing triggered
Then
if Market Price > Entry Price then close 40 and Stop = Entry
If Entry Price – Market Price > 15 then Close 40 and limit = Entry +10
If Entry Price -Market Price <15 then Stop = 16 and limit = Entry +5
Notes: As IG will withhold margin for any order all the Close orders should be in limit format not a new order. Also Is it possible to set the order type as Force Open instead of Net postion?
Thanks
A
08/14/2021 at 6:16 AM #175272Fees and spread are not known automatically.
What do you mean by “and limit = Entry +10“ (or 5)?
What do you mean by “As IG will withhold margin for any order all the Close orders should be in limit format not a new order”?
08/14/2021 at 6:59 AM #175275Hi Roberto
PLease see below:
What do you mean by “and limit = Entry +10“ (or 5)?
I know limit is confusing here in other platform limit is the price that you want to enter the market but in IG limit is somehow equal to target/take profit.
In IG platform when you create an order there are three fields, Price level = price you want to open postion, Stop= Stop, Limit = take profit/Target .
What do you mean by “As IG will withhold margin for any order all the Close orders should be in limit format not a new order”?
This is what I am doing manually now: I buy at market 80 contract, and at same time I create 3 sell orders of 40 contract at price level of Entry +20 , 20 contract at Entry +30 and 10 Contract at Entry +40. So when I do this in the platform IG will withhold Margin for all of my orders that means with this strategy I would need margin for at least 160 contract.So if I dont want to use my margin on the sell orders, I have to monitor the charts 24/7 and wait until it meets my criteria and go to the position and partially close the contracts that I want. Other workaround is instead of buying 80 contracts I open 4 different positons at the same time with different limits( targets)
What I am looking for in PRT is to be able to automate this . In the rules when I say “If Market Price – Entry = 40 then Close 10” I dont want the PRT create a new order that use my margin but just partially close 10 contracts (like I am doing it manually) when it reaches to +40.
Hope it is clear now.
Thanks
08/14/2021 at 9:23 AM #175285There’s no need for a FORCE OPEN instruction, as opening opposite positions is not allowed in a single strategy (multipole different strategies can, provided you have set Force Open with IG).
There you go (I tested it on DAX, 1h TF):
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121DEFPARAM CumulateOrders = FALSE//initialisationIf Not OnMarket THENEntryPrice = 0Ohour = 0 //Hour when a trade opensOmin = 0 //Minute when a trade opensFlag = 0LotSize = 80ENDIF//update EntryPrice after entering at marketIF OnMarket AND Not OnMarket[1] THENEntryPrice = TradePriceENDIFIF OnMarket AND IntraDayBarIndex = 0 THENFlag = 1ENDIF//set entry conditionsSma100 = average[100,0](close)Cond = (close CROSSES OVER Sma100) AND Not LongOnMarket//enter at MarketIF Cond THENBUY LotSize Contracts AT MarketEntryPrice = closeOhour = OpenHourOmin = OpenMinuteHlimit = Ohour + 4 //limit of 4 hours after entryHlimit = Hlimit - (24 * (Hlimit > 23))TimeLimit = ((Hlimit * 100) + Omin) * 100 //let's make it 6 digitsENDIF//IF OnMarket THENPips = PositionPerf * PositionPrice / PipSizeNpos = abs(CountOfPosition)IF ((OpenTime >= Hlimit) OR ((OpenTime <= Hlimit) AND (Flag = 1))) OR (OpenTime >= 140000) THENIF (Pips > 15) AND (Npos = LotSize) THENSELL 40 Contracts AT MarketNewSL = EntryPrice + 10 * PipSizeELSIF (Pips > 0) AND (Npos = LotSize) THENSELL 40 Contracts AT MarketNewSL = EntryPriceELSIF (PipS > 0) AND (Pips < 15) THENSELL 16 Contracts AT MarketNewSL = EntryPrice + 5 * PipSizeENDIFELSEIF (Pips >= 20) AND (Npos = LotSize) THENSELL 40 Contracts AT MarketENDIFIF Pips >= 30 THENSELL 20 Contracts AT MarketENDIFIF Pips >= 40 THENSELL 10 Contracts AT MarketENDIFENDIFENDIF//// https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/// (righe 17- 56)////trailing stop functiontrailingstart = 20 //25 trailing will start @trailinstart points profittrailingstep = 5 //20 trailing step to move the "stoploss"distance = 10 //10 pips distance from caurrent price (if required by the broker)//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THENnewSL = tradeprice(1)+trailingstep*pipsizeENDIF//next movesIF newSL>0 AND close-newSL>=trailingstep*pipsize THENnewSL = newSL+trailingstep*pipsizeENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THENnewSL = tradeprice(1)-trailingstep*pipsizeENDIF//next movesIF newSL>0 AND newSL-close>=trailingstep*pipsize THENnewSL = newSL-trailingstep*pipsizeENDIFENDIF//stop order to exit the positionsIF newSL>0 THENIF LongOnMarket THENIF (close + distance) > newSL THENSELL AT newSL STOPELSIF (close - distance) < newSL THENSELL AT newSL LIMITELSESELL AT MarketENDIFELSIF ShortOnmarket THENIF (close + distance) < newSL THENEXITSHORT AT newSL STOPELSIF (close - distance) > newSL THENEXITSHORT AT newSL LIMITELSEEXITSHORT AT MarketENDIFENDIFENDIF//*********************************************************************************//graph Pips//graph Hlimit//graph Ohour//graph Omin//graph TimeLimit//graph Npos//graphonprice NewSL1 user thanked author for this post.
08/14/2021 at 1:32 PM #17533408/14/2021 at 2:15 PM #175338Thanks for reply , I can see that there is an entry condition. I would like to manually enter the market with no condition when I press start the autotrade. So basically I am more interested in closing the positions with Autotrade not openning the positons.
08/14/2021 at 3:24 PM #175341Remove line 18 and replace line 19 with this one:
1Cond = Not OnMarketIt will then enter again as soon as the trade is closed.
-
AuthorPosts
Find exclusive trading pro-tools on