Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 756
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Good afternoon.
I've written an exercise programme. It's not working for some reason.
I tested it in the strategy tester between September 29 and October 15.
The program should work like this: I make a buy. When the price falls to 0.010 it should sell with a loss.
A buy occurs. There is no sale. I start visualization and see that the price is not just 0.010 lower but much higher. Strange.
// -------- variables --- Start -----
extern double L1=0.01; // lot size for buying
extern double L1n=0.01; // lot size for buying (normalized lot)
extern double AktualAsk=0.0; // current bid price
extern double AktualBid=0.0; // actual selling price
extern int int ticketlackmus=1; // indicator of successful order opening.
extern int int ticket1=0; // ticket
extern bool PozOtk1=true;
// -------- variables --- End -----
int init()
{
return(0);
}
int start()
{
if (PozOtk1==true)
{
//open position
ticketlackmus=1;
while (ticketlackmus>0)
{
Alert (" Open first position ");
RefreshRates();// Refresh data
AktualAsk=NormalizeDouble(Ask,Digits); //for price
L1n=NormalizeDouble(L1,2); //for the lot.
ticket1=OrderSend ("GBPUSD", OP_BUY, L1n, AktualAsk, 5, 0, 0, 0, 0, CLR_NONE);
if (ticket1>0) ticketlackmus=-1;
{
Alert (" ORDER OPEN ", ticket1, ", ticketlackmus);
}
}
PozOtk1=false;
Alert (" PozOtk1 ", PozOtk1);
}
RefreshRates();// RefreshRates()
AktualBid=NormalizeDouble(Bid,Digits); //for price
if (AktualBid<=AktualAsk-0.010 && PozOtk1==false)
{
RefreshRates(); // Refresh data
OrderSelect(ticket1, SELECT_BY_TICKET;)
L1n=NormalizeDouble(L1,2); //for the lot
OrderClose (ticket1, L1n, AktualBid, 5);
PozOtk1=true;
}
return(0);
}
int deinit()
{
return(0);
}
Ozero.
Please use the magic SRC button when inserting code:
Insert code correctly in the forum
If a position is opened at a certain symbol (in this case - "GBPUSD"), then it is advisable to take all data on this symbol through marketinfo, i.e. not just AktualAsk=NormalizeDouble(Ask,Digits ); aktualAsk=MarketInfo( "GBPUSD",MODE_ASK);
And so any market data should be taken, in order to avoid.
If a position opens on a specific symbol (in this case - "GBPUSD"), then it is advisable to take all data also on this symbol via marketinfo, i.e. not just AktualAsk=NormalizeDouble(Ask,Digits); aktualAsk=MarketInfo( "GBPUSD",MODE_ASK);
And so any market data should be taken, to avoid.
Thank you Evillive!
I have made changes. But I have already started buying. No sale after the changes. M15 test from September 30, 2014 to mid-October.
Thanks, Evillive!
Made the change. But, the purchase was going on anyway. After the changes, no sale takes place. M15 test from 30 September 2014 to mid October.
OrderClose (ticket1, L1n, AktualBid, 5);
I meant the order doesn't close :( Sorry if I didn't put it that way, I'm still a beginner.
It's working quite well.