Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 350

 
Forexman77:


In the picture, I have marked with an arrow where the output should be. I don't understand what the problem is. We go in, remember the time,

Then exit when the time is longer than the entry with an offset by one period and the price is below the 3-day MA min.

The code is as follows:

What do you think?


I mean it would be good to post screenshots where you can see the price and the timeframe. Maybe there is pipsing on M1 and the server just does not have time to process the order in time.


And instead of t=Time[0]; better use OrderOpenTime().

 
evillive:

If it's not too secret, I mean it would be good to publish screenshots where you can see prices and timeframe. Maybe there is pipsing on M1 and the server just does not have time to process the order.


Use OrderOpenTime() instead of t=Time[0];.

Eureka! I understood why.

signal > 0.006 almost always, so t=Time[0]; is updated all the time and the trade does not close.

I put t=Time[0]; in the block where the fact of opening of a position is announced.

 

Hi all, how does the EA being tested behave against gaps? I.e. on the test it shows good profit, but on the demo it has been gapping everything for two days already :(.

 

Hi all!

I have made EA by crossing two EMAs, this is my first EA and i am afraid i made some silly mistakes, so i am asking the professionals to review the code and give me some advice if something is wrong.

This EA should trade on bitcoin exchange, the price may jump by 30% per day, so stoploss and takeprofit should be in percent of price.

I have tested it on demo account, it seems to work, but I am afraid to use it on real account, the minimum lot is about $ 7, and cent account has no broker.

I have not attached trailing stop yet, and I'm going to compare EMA difference not with zero, but with some small value, to avoid frequent trades when curves run parallel.

The program is mostly made up of bits and pieces plucked from examples and tutorials, so there's a concern that I might have messed up somewhere when putting it together.

Variables:

#property copyright "me"
#property link      "killnosock.net"
extern int SlowEma = 21;
extern int FastEma = 10;
extern int MaxRisk = 100;// % депо которое будет использоваться для открытия ордера
extern int  TakeProfit=100;
extern int  StopLoss=100;
extern int Slippage = 10;

int LastBars = 0;

int init(){return(0);}
int deinit() {return(0);}

This function defines lot size:

double GetLot(int Risk)
{double Free    =AccountFreeMargin();
 double One_Lot =MarketInfo(Symbol(),MODE_MARGINREQUIRED);
 double Min_Lot =MarketInfo(Symbol(),MODE_MINLOT);
 double Max_Lot =MarketInfo(Symbol(),MODE_MAXLOT);
 double Step    =MarketInfo(Symbol(),MODE_LOTSTEP);
 double Lot     =MathFloor(Free*Risk/100/One_Lot/Step)*Step;
 if(Lot<Min_Lot) Lot=Min_Lot;
 if(Lot>Max_Lot) Lot=Max_Lot;
 if(Lot*One_Lot>Free) {
 Alert(" free= ", AccountFreeMargin()," for one lot= ", MarketInfo(Symbol(),MODE_MARGINREQUIRED)," lot= ", Lot);
 return(0.0);}
return(Lot);}

We open an order here:

int NewOrder(int Cmd,double Lot)
{double TP=0; //takeprofit
 double SL=0; //stoploss
 double PR=0; //price
 color clr = CLR_NONE;
 while(!IsTradeAllowed()) Sleep(10);
 RefreshRates();
 if(Cmd==OP_BUY)
   {PR=Ask;
    if(TakeProfit>0) TP=Ask + Ask*TakeProfit/100;
    if(StopLoss>0) SL=Ask - Ask*StopLoss/100;
    if(SL<0) SL = 0;
    if(TP<0) TP = 0;
    clr = Green;}
 if(Cmd==OP_SELL)
   {PR=Bid;
    if(TakeProfit>0) TP=Bid - Bid*TakeProfit/100;
    if(StopLoss>0) SL=Bid + Bid*StopLoss/100;
    if(SL<0) SL = 0;
    if(TP<0) TP = 0;
    clr = Red;}
 int tic=OrderSend(Symbol(),Cmd,Lot,PR,Slippage,SL,TP,"",0,0,clr);
 if(tic<0) Print("Open order error: ",GetLastError());
return(tic);}

Here we close 1 or all orders

//CloseOrder
void CloseOrder()
{double PR=0;
 while(!IsTradeAllowed()) Sleep(10);
 RefreshRates();
 if(OrderType()==OP_BUY)  PR=Bid;
 if(OrderType()==OP_SELL) PR=Ask;
 if(!OrderClose(OrderTicket(),OrderLots(),PR,Slippage,CLR_NONE))
   Print("Order close error: ",GetLastError());
return;}

//Close all Orders
void CloseAllOrders()
{
  for(int i=OrdersTotal()-1;i>=0;i--)
   if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
     {
      CloseOrder();
     }
return;}

This function calculates the difference of two EMAs

double EmaDiff(int shift)
   {
      double difference;
      difference = iMA(Symbol(),0,FastEma,0,MODE_EMA,PRICE_CLOSE,shift)
                 - iMA(Symbol(),0,SlowEma,0,MODE_EMA,PRICE_CLOSE,shift);
      return(difference);
   }

And here is the body of the program

int start()
  {
double Lot;
    // действуем, когда открывается новая свечка
    if (LastBars == Bars) return(0);
    else LastBars = Bars;
      {         
         if ((EmaDiff(1) > 0) && (EmaDiff(2) < 0))
            {
               CloseAllOrders();
               Lot = GetLot(MaxRisk);
               NewOrder(OP_BUY,Lot);
            }
            
         if ((EmaDiff(2) > 0) && (EmaDiff(1) < 0))
            {
               CloseAllOrders();
               Lot = GetLot(MaxRisk);
               NewOrder(OP_SELL,Lot);
            }                    
      }
   return(0);
  }
 

Dear Sirs hello all!!!

Help me make out the deals!!! There is a set with deals, I downloaded it from a site where there was a contest where the guy with $10000 for a month or a week I do not remember made $300 000! How can I tell where he closed the deal!!! Opening time, price, lot, currency pair all there!!!

.........................................................................................................................................................................................................................................


THERE ARE SO MANY TRADES, I DO NOT KNOW WHERE HE CLOSED THEM ALL!


Results are displayed as of 2013-08-29 14:02:05(EET)


TRANSACTION TIME TYPE LOTS SYMBOL PRICE SWAP PROFIT

272984 2013-08-05 07:58:50 SELL 1.00 EURAUD 1.49556 0 0

272986 2013-08-05 07:58:56 SELL 1.00 EURAUD 1.49553 0 0

272988 2013-08-05 07:59:03 SELL 1.00 EURAUD 1.49549 0 0

272999 2013-08-05 07:59:57 SELL 1.00 EURAUD 1.49534 0 0

273002 2013-08-05 08:00:02 SELL 1.00 EURAUD 1.4954 0 0

273004 2013-08-05 08:00:07 SELL 1.00 EURAUD 1.4954 0 0

284429 2013-08-05 16:47:27 BUY 1.00 EURAUD 1.48839 0 628.85

284432 2013-08-05 16:47:33 BUY 1.00 EURAUD 1.48838 0 629.71

284433 2013-08-05 16:47:37 BUY 1.00 EURAUD 1.48843 0 625.28

284435 2013-08-05 16:47:43 BUY 1.00 EURAUD 1.48857 0 612.81

284439 2013-08-05 16:47:47 BUY 1.00 EURAUD 1.48854 0 615.46

284442 2013-08-05 16:47:50 BUY 1.00 EURAUD 1.48859 0 611.01

284443 2013-08-05 16:47:51 BUY 1.00 EURAUD 1.48859 0 0

284447 2013-08-05 16:48:01 BUY 1.00 AUDUSD 0.89056 0 0

284449 2013-08-05 16:48:09 SELL 1.00 EURAUD 1.48735 0 -110.44

284451 2013-08-05 16:48:21 BUY 1.00 AUDUSD 0.89061 0 0

284454 2013-08-05 16:48:25 BUY 1.00 AUDUSD 0.8906 0 0

284458 2013-08-05 16:48:30 BUY 1.00 AUDUSD 0.89058 0 0

284461 2013-08-05 16:48:34 BUY 1.00 AUDUSD 0.89051 0 0

284465 2013-08-05 16:48:39 BUY 1.00 AUDUSD 0.89052 0 0

284469 2013-08-05 16:48:43 BUY 1.00 AUDUSD 0.89053 0 0

284472 2013-08-05 16:48:47 BUY 1.00 AUDUSD 0.89051 0 0

284475 2013-08-05 16:48:51 BUY 1.00 AUDUSD 0.89056 0 0

284479 2013-08-05 16:48:55 BUY 1.00 AUDUSD 0.89056 0 0

284483 2013-08-05 16:48:59 BUY 1.00 AUDUSD 0.89056 0 0

284487 2013-08-05 16:49:03 BUY 1.00 AUDUSD 0.89058 0 0

284491 2013-08-05 16:49:08 BUY 1.00 AUDUSD 0.89053 0 0

284492 2013-08-05 16:49:12 BUY 1.00 AUDUSD 0.89053 0 0

286130 2013-08-05 16:51:55 BUY STOP 1.00 AUDUSD 0.8915 0 0

288418 2013-08-05 16:52:05 BUY STOP 1.00 AUDUSD 0.89255 0 0

293964 2013-08-05 16:52:14 BUY STOP 1.00 AUDUSD 0.8935 0 0

299297 2013-08-05 16:52:26 BUY STOP 1.00 AUDUSD 0.89459 0 0

299482 2013-08-05 16:52:35 BUY STOP 1.00 AUDUSD 0.89553 0 0

299533 2013-08-05 16:52:53 BUY STOP 1.00 AUDUSD 0.89655 0 0

299595 2013-08-05 16:53:02 BUY STOP 1.00 AUDUSD 0.89703 0 0

300040 2013-08-05 16:53:36 BUY STOP 1.00 AUDUSD 0.89751 0 0

300096 2013-08-05 16:53:46 BUY STOP 1.00 AUDUSD 0.898 0 0

300151 2013-08-06 07:54:49 SELL 1.00 AUDUSD 0.89756 4.36 519.04

300153 2013-08-06 07:54:53 SELL 1.00 AUDUSD 0.89749 4.36 512.04

300154 2013-08-06 07:54:58 SELL 1.00 AUDUSD 0.89743 4.36 506.04

300156 2013-08-06 07:55:01 SELL 1.00 AUDUSD 0.89738 4.36 501.04

300158 2013-08-06 07:55:05 SELL 1.00 AUDUSD 0.89736 4.36 499.04

300160 2013-08-06 07:55:11 SELL 1.00 AUDUSD 0.89772 4.36 535.04

300161 2013-08-06 07:55:15 SELL 1.00 AUDUSD 0.89771 4.36 534.04

300163 2013-08-06 07:55:19 SELL 1.00 AUDUSD 0.89765 4.36 528.04

300167 2013-08-06 07:55:36 SELL 1.00 AUDUSD 0.89733 4.36 496.04

300169 2013-08-06 07:55:40 SELL 1.00 AUDUSD 0.89733 4.36 496.04

300171 2013-08-06 07:55:44 SELL 1.00 AUDUSD 0.89735 4.36 498.04

300173 2013-08-06 07:55:49 SELL 1.00 AUDUSD 0.89732 4.36 495.04

300178 2013-08-06 07:55:52 SELL 1.00 AUDUSD 0.89725 4.36 488.04

300181 2013-08-06 07:55:56 SELL 1.00 AUDUSD 0.89714 4.36 477.04

 
FEAR:

Dear Sirs hello all!!!

Help me make out the deals!!! There is a set with deals, I downloaded it from a site where there was a contest where the guy with $10000 for a month or a week I do not remember made $300 000! How can I tell where he closed the deal!!! Opening time, price, lot, currency pair all there!!!

.........................................................................................................................................................................................................................................

THERE ARE SO MANY TRADES, I DO NOT KNOW WHERE HE CLOSED THEM ALL!

There's no way, they don't specify a closing time and price, there's no freebies ))))
 
evillive:
There is no way, they do not specify closing price on purpose, there is no free())


I UNDERSTAND BUT THERE IS A LOT AND A PRICE AND A BUY OR SELL FOR EXAMPLE:


284429 2013-08-05 16:47:27 BUY 1.00 EURAUD 1.48839 0 628.85

THE PRICE IS 1.48839 CURRENCY PAIR -EURAUD, LOT 1 BROKER 5 MARK!!! PROFIT 628 I.E. THE PRICE WENT 628 PIPS UP!!! at lot 1!!! i mean if you can look at the history, i don't understand, honestly the time is almost 17:00 but the price is much lower than this 1.48839!!! EVEN IF THIS IS THE CLOSING PRICE I COUNTED 7000 PIPS I DO NOT UNDERSTAND HOW

 
FEAR:


I UNDERSTAND BUT THERE IS A LOT AND A PRICE AND A BUY OR SELL FOR EXAMPLE:


284429 2013-08-05 16:47:27 BUY 1.00 EURAUD 1.48839 0 628.85

THE PRICE IS 1.48839 CURRENCY PAIR -EURAUD, LOT 1 BROKER 5 MARK!!! PROFIT 628 I.E. THE PRICE WENT 628 PIPS UP!!! at lot 1!!! i mean if you can look at the history, i don't understand, honestly the time is almost 17:00 but the price is much lower than this 1.48839!!! EVEN IF IT'S THE CLOSING PRICE I COUNTED 7000 PIPS I DON'T UNDERSTAND HOW THAT'S POSSIBLE


Where did you count 7000 pips? It's the opening price, but even if it were the closing price, one price is not enough to count something there, you still need both of them. I think it's just a fake, unless the contest ran until December 18, when this position could have been closed with 630 pips profit. But before that he would have been forced to sit out a drawdown of about -830 pips (for 4zn), not very clever, the strategy is such a dismal guano...


I would have lost it on the real account, it works on a demo when I have a lot of virtual money)))

 

evillive, good afternoon, thank you for pointing me in the right direction!!!



r772ra, hello, thank you for explaining the error exhibiting the corrected code (I consider this the best way to learn (practice (-Do the theory, my friend, and the tree of life is evergreen.-))).

 
Please help me fix the errors in this function. It has already squeezed all the juice out of me. The essence of the function, when it reaches a certain profit, the function should close half of the order.
void CloseHalfOrder(){

for (int i = 0; i<=OrdersTotal(); i++)
{
if (OrderSelect (i,SELECT_BY_POS,MODE_TRADES) == true)
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderProfit()>= NormalizeDouble (TP*Point,Digits))
{
if (OrderType() == OP_BUY)
double Lots = OrderLots();
double HalfLot = NormalizeDouble (Lots*0.5,2);
OrderClose(OrderTicket(),HalfLot,Bid,0,HotPink);

if (OrderType() == OP_SELL)
double Lots1 = OrderLots();
double HalfLot1 = NormalizeDouble (Lots*0.5,2);
OrderClose(OrderTicket(),HalfLot1,Ask,0,HotPink);
}
}
}
}

Oh, and how do I make this function work only once per open order?
Reason: