I developed a strategy - Is it possible to use it with metatrader?

 

hi,

i developed a strategy but i'm not sure if it is possible to use it with metatrader. maybe you guys can tell me if it's possible to code this one.

i would like to use the strategy on a 5 minutes candlestick chart. every time a new 5 minutes candle shows up, there should be a buy order combined with a take-profit-limit 5 pips above the buy rate and a stop-loss-limit at 5 pips under the buy rate.

example: cfd bought at 6000, so take-profit should be at 6005 and stop-loss at 5995.

if the stop-loss or take-profit limit is not reached, the order should be closed at the last second of the 5-minute-candle and a new buy-trade combined with a take-profit and stop-loss order should be initiated at the first second of the following 5-minute-candle.

if the stop-loss or take-profit order is reached, the trade will be closed and a new buy-trade combined with a new take-profit and stop-loss order should be initiated in the first second of the following 5-minute-candle.

is it possible to code this ea and use it with metatrader?




and theres one other question i got: how come that the close-value of a candle and the open-value of the following candle are sometimes different? at every other chartsoftware the close-value and open-value of the following candle are the same. is it a bug in metatrader?

 
and a stop-loss-limit at 5 pips under the buy rate.

5pip stoploss is not likely possible depending on the broker's mandatory stop-level. You can setup your code to close the position on its own when it hits your shallow stops.

5pips will be messy though as you have to consider the spread is going to eat much of that. buying a cdf at 6000 (meaning the ask price is 6000) and setting your stops at 5995 would be disasterous if the spread was 4pips.

and theres one other question i got: how come that the close-value of a candle and the open-value of the following candle are sometimes different? at every other chartsoftware the close-value and open-value of the following candle are the same. is it a bug in metatrader?


Not a bug, just a market reality, like spread.

 
bool New_Bar=false;
extern double Lots = 1.0;
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
int total, cnt;
//------------------------------------------------------------------+
Fun_New_Bar();
if (New_Bar == false)
return;
//------------------------------------------------------------------+
{
//BUY triger Start---------------------------------------------------+
//Close the OPEN orders
total=OrdersTotal();
for(cnt=total-1;cnt>=0;cnt--)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
//-----
if(OrderType()==OP_BUY && OrderSymbol()== Symbol()&& OrderComment()== "Normal")
{
//Close the BUY order
OrderClose(OrderTicket(),OrderLots(),Bid,5,CLR_NONE); // close position
Alert(Symbol(),": CLOSE the BUY Order ", OrderTicket());
//--------------------
}
}
//-----
//-----
{
//Open the BUY order
OrderSend (Symbol(),OP_BUY,Lots,Ask,5,0,0,"Normal",255,0,CLR_NONE);
//Modify the last order by adding StopLoss and TakeProfit
total=OrdersTotal();
for(cnt=total-1;cnt>=0;cnt--)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()==OP_BUY && OrderSymbol()== Symbol()&& OrderComment()== "Normal")
{
OrderModify(OrderTicket(),5,OrderOpenPrice()-(250*Point),OrderOpenPrice()+(700*Point),0,CLR_NONE);
}
}
Alert(GetLastError());
//
//return;
}
}
//BUY Triger Finish

return(0);
}
//+------------------------------------------------------------------+
void Fun_New_Bar()
{
static datetime New_Time = 0;
New_Bar = false;
if (New_Time!= Time[0])
{
New_Time = Time[0];
New_Bar = true;
}
}
//-------------------------------------------------------------------+
 

thank you for your reply phillip.

lets assume the ask is at 6000 and the bid is at 5996 (=4 point spread). i buy long at the ask price of 6000 and the stop loss ist set at 5995. so the position will be closed, when the ask line of 6000 touches the stop loss at 5995. right?
or will the trade be closed wenn the bid-line which was at 5996 when i opened the trade, touches the stop-loss at 5995?

limits for take-profit and stop-loss have to be at least 5 points away from the buy value and spreads are between 2 and 4 points at fxcm. i got a excel list of quotations from fxcm where i calculated everything. there are some german words in it but if you want i can post the file so you can have a look.

 
the trade be closed wenn the bid-line which was at 5996 when i opened the trade, touches the stop-loss at 5995?

This.

For long positions you "buy-in" at the ask price, you "close out" at the bid price. Vice versa for short positions.
 
1005phillip wrote >>
This.

For long positions you "buy-in" at the ask price, you "close out" at the bid price. Vice versa for short positions.

okay. when the ask is at 6000 and the bid is at 5996 (=4 points spread), to get a overall profit of 5 points, the bid must raise to 6005, right?
if the bid lowers to 5991 i got a overall loss of 9 points, right?
 
mackdaddy wrote >>

okay. when the ask is at 6000 and the bid is at 5996 (=4 points spread), to get a overall profit of 5 points, the bid must raise to 6005, right?
if the bid lowers to 5991 i got a overall loss of 9 points, right?


You got it. Every position you open immediately starts out its life underwater by an amount equal to the spread. If the ask is 6000 and the bid is 5996 then you pay 6000 to open the position but it is only worth 5996 if you try and sell it immediately. If you set the stoploss 5pips below the bid at open then you are really operating with a 9 pip stoploss (you stand to lose 9 pips worth of equity if your stops are hit). Conversely if you want to profit by a mere 5 pips then you need that bid price to climb 9 pips to reach 6005, netting you 5 pips but requiring a 9pip market move in your favor.

5pip (and 9pip) market moves are really just operating in the noise. Scalpers like to try and skim profits off the market in this single-digit pip regime but I don't know of a single scalper that has made money even short-term (6 months) let alone sustainably for years. If you really want to just gamble your money then I'd personally recommend hitting Vegas instead of trying to scalp in forex as the entertainment for your dollar will be much much higher but the net effect on your bank account will be the same.
 

okay thanks for your help. looks like i gotta rethink my strategy... :)

Reason: