Hello!
I would need script for MT4 like this. Can someone code it for me, and for what price?
If anybody codes this for you for money it would simply be stealing from you.
You may well be able to optimize the pip difference so that on a particular pair, over a particular time frame, the method is successful. When you actually trade it you will lose money. With a 10 pip difference and a 2 pip spread you will lose money quite quickly. If, for example, you use a 50 pip difference you will at least lose money more slowly (using a smaller lotsize to keep the same risk per trade of course).
This is a
NOT
a simple strategy to code (even for testing purposes). It would be easier if you just opened and closed positions without all these limit orders and changing TP levels.My calculation shows only four possible trade outcomes.
Number the trades 1 to 3, with 1 being first.
< 1 > < 2 > < 3 >
+1 ---- ----- = +1
0 +1 ----- = +1
-1 0 +1 * 2 = +1
-3 -2 -1 * 2 = -7
If the wins earn 10$, the loss will cost $70.
This is a horrible method to code and I haven't even put in the SHORT position. I got bored with it well before the second hour of work, but got it working anyway, despite its worthlessness.
#include <WinUser32.mqh> #define ADVISORNAME "Marty: v0.01" #define MAGICNUMBER 3482936 // this is used by multiplying by 10 and adding 1 , 2 or 3 to identify the orders extern string _= "GRID is in POINTS"; extern int GRID=2000; extern double LOTSIZE= 0.1; bool abort = false; int ticket=-1; int previousActiveTrades=0; int sleep=0; int lastHour=0; //---------------------------------------------------------------------------------------------------- int init(){ if( LOTSIZE < MarketInfo(Symbol(),MODE_MINLOT) ) LOTSIZE = MarketInfo(Symbol(),MODE_MINLOT); if( GRID < 2*MarketInfo(Symbol(),MODE_STOPLEVEL) ) GRID = 2*MarketInfo(Symbol(),MODE_STOPLEVEL); previousActiveTrades = CountActiveTrades(); if( previousActiveTrades > 0 ){ MessageBox( "ERROR: Trades in progress.", ADVISORNAME, MB_ICONSTOP ); abort=true; } return(0); } //---------------------------------------------------------------------------------------------------- int start(){ if( abort ) return( 0 ); if( sleep > 0 ){ // wait for a random number of hours before entering the market again if( lastHour == Hour() ) return( 0 ); sleep--; return( 0 ); } int activeTrades = CountActiveTrades(); if( activeTrades != previousActiveTrades ) Print( activeTrades + " active trades" ); if( activeTrades==1 ) // uninteresting case with nothing to do return( 0 ); if( activeTrades == 0 ){ // either trades were closed or we are starting from scratch if( previousActiveTrades > 0 ){ if( !KillPendingOrders() ){ Print("Failed to kill all pending orders"); abort = true; } previousActiveTrades=0; sleep = 3 + (MathRand() % 15 ); return( 0 ); } if( !PlaceLONGposition() ){ Print("Failed to place all LONG positions"); abort = true; // this may not be the best handling, but something is wrong so just stop further trading return( 0 ); } previousActiveTrades = CountActiveTrades(); return( 0 ); } if( activeTrades==2 ){ if( previousActiveTrades==1 ){ // a buy stop order was triggered so we need to move the TP on order #1 if( !MoveTP_OrderTwo() ){ Print("Failed to move single TP level"); abort=true; } previousActiveTrades=2; return( 0 ); } return( 0 ); } if( activeTrades==3 ){ if( previousActiveTrades==2 ){ // a buy stop order was triggered so we need to move the TP on order #1 and #2 if( !MoveTP_OrderThree() ){ Print("Failed to move both TP levels"); abort=true; } previousActiveTrades=3; return( 0 ); } return( 0 ); } return( 0 ); } //---------------------------------------------------------------------------------------------------- bool PlaceLONGposition(){ int n; double price, LONGstopLoss, LONGtakeProfit; for( n=0; n<2; n++ ){ LONGtakeProfit = NormalizeDouble( Ask + GRID*Point, Digits ); LONGstopLoss = NormalizeDouble( Ask - 3*GRID*Point, Digits ); ticket= OrderSend( Symbol(), OP_BUY, LOTSIZE, Ask, 10, LONGstopLoss, LONGtakeProfit, ADVISORNAME, 10*MAGICNUMBER+1 ); if( ticket != -1 ) break; while( !RefreshRates() ){ // wait for a new tick } } if( ticket== -1 ) return( false ); // order was not placed RefreshRates(); for( n=0; n<2; n++ ){ LONGtakeProfit = NormalizeDouble( Ask , Digits ); price = NormalizeDouble( Ask - GRID*Point, Digits ); ticket= OrderSend( Symbol(), OP_BUYLIMIT, LOTSIZE, price, 10, LONGstopLoss, LONGtakeProfit, ADVISORNAME, 10*MAGICNUMBER+2 ); if( ticket != -1 ) break; while( !RefreshRates() ){ // wait for a new tick } } if( ticket== -1 ) return( false ); // order was not placed for( n=0; n<2; n++ ){ LONGtakeProfit = NormalizeDouble( Ask - GRID*Point, Digits ); price = NormalizeDouble( Ask - 2*GRID*Point, Digits ); ticket= OrderSend( Symbol(), OP_BUYLIMIT, 2*LOTSIZE, price, 10, LONGstopLoss, LONGtakeProfit, ADVISORNAME, 10*MAGICNUMBER+3 ); if( ticket != -1 ) break; while( !RefreshRates() ){ // wait for a new tick } } if( ticket== -1 ) return( false ); // order was not placed return( true ); } //---------------------------------------------------------------------------------------------------- bool MoveTP_OrderTwo(){ // we are going to copy the TP from OrderTwo to OrderOne double price = -1.0; for( int n=OrdersTotal()-1; n>=0; n-- ){ if( !OrderSelect(n,SELECT_BY_POS) ) continue; if( OrderSymbol() != Symbol() ) continue; if( OrderMagicNumber() != (10*MAGICNUMBER+2) ) // order number 2 in the group continue; price = OrderTakeProfit(); break; } if( price < Ask ){ Print("Wrong Price found"); return( false ); } for( n=OrdersTotal()-1; n>=0; n-- ){ if( !OrderSelect(n,SELECT_BY_POS) ) continue; if( OrderSymbol() != Symbol() ) continue; if( OrderMagicNumber() != (10*MAGICNUMBER+1) ) // the first order in the group continue; if( !OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),price,0) ){ abort=true; return( false ); } } return( true ); } //---------------------------------------------------------------------------------------------------- bool MoveTP_OrderThree(){ // we are going to copy the TP from OrderThree to OrderOne and OrderTwo double price = -1.0; for( int n=OrdersTotal()-1; n>=0; n-- ){ if( !OrderSelect(n,SELECT_BY_POS) ) continue; if( OrderSymbol() != Symbol() ) continue; if( OrderMagicNumber() != (10*MAGICNUMBER+3) ) // order number 3 in the group continue; price = OrderTakeProfit(); break; } if( price < Ask ) return( false ); for( n=OrdersTotal()-1; n>=0; n-- ){ if( !OrderSelect(n,SELECT_BY_POS) ) continue; if( OrderSymbol() != Symbol() ) continue; // the first or second orders in the group if( OrderMagicNumber() != (10*MAGICNUMBER+1) && OrderMagicNumber() != (10*MAGICNUMBER+2) ) continue; if( !OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),price,0) ){ abort=true; return( false ); } } return( true ); } //---------------------------------------------------------------------------------------------------- int CountActiveTrades(){ int count=0; for( int n=OrdersTotal()-1; n>=0; n-- ){ if( !OrderSelect(n,SELECT_BY_POS) ) continue; if( OrderSymbol() != Symbol() ) continue; if( (OrderMagicNumber()/10) != MAGICNUMBER ) continue; if( OrderType()==OP_BUY || OrderType()==OP_SELL ) // we are not counting any pending orders count++; } return( count ); } //---------------------------------------------------------------------------------------------------- bool KillPendingOrders(){ bool success= true; for( int n=OrdersTotal()-1; n>=0; n-- ){ if( !OrderSelect(n,SELECT_BY_POS) ) continue; if( OrderSymbol() != Symbol() ) continue; if( (OrderMagicNumber()/10) != MAGICNUMBER ) continue; if( OrderType()!=OP_BUY && OrderType()!=OP_SELL ){ // then it must be some sort of stop or limit order if( !OrderDelete(OrderTicket()) ) success = false; // failure means we tried to delete a relevant pending order but failed } } return( success ); }
If anybody codes this for you for money it would simply be stealing from you.
You may well be able to optimize the pip difference so that on a particular pair, over a particular time frame, the method is successful. When you actually trade it you will lose money. With a 10 pip difference and a 2 pip spread you will lose money quite quickly. If, for example, you use a 50 pip difference you will at least lose money more slowly (using a smaller lotsize to keep the same risk per trade of course).
This is a
NOT
a simple strategy to code (even for testing purposes). It would be easier if you just opened and closed positions without all these limit orders and changing TP levels.
Do you still think it will be stealing.... If you read the procedure here https://www.mql5.com/en/articles/117
The coder has to code this whole EA for buy and sell trades
check his coding and beside that before the coder can begin the job the coder has to come to a workagreement with customer
If the job is not done according the Requirements Negotiation then where is the payment ???
It takes far more time then only coding the EA... Beside that the customer is the one that makes the workagreement
I helped people at JOBS not only coding but also do some explanation about it.... That's no Stealing in my idea
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello!
I would need script for MT4 like this. Can someone code it for me, and for what price?
For instance: