Need internal Trailing Stop function to bypass broken limitation...

 

Hi!

I made a simple internal trailing stop that doesnt work...

I don't want to officially include a stoploss in the order cause they don't allow stoploss below 200points...

Here's my unworking script:

//Trailing Stop
int TrailingStop()
{double Trailing;
for (int C = 0; C < Total; C ++)
{OrderSelect(C, SELECT_BY_POS, MODE_TRADES);
Trailing = NormalizeDouble(Bid-(Point*(50+Spread)),Digits);
if (Trailing > StopLevel)
StopLevel = Trailing;
if (Bid <= StopLevel)
OrderClose(OrderTicket(), OrderLots(), Bid, 0, White);}
return(0);}

//----------------


Please give me some help!!!

Thanks!

GAB

 

What do you mean "doesn't work"...?

When you are looping through orders, it's safer to start C = (Total - 1) and then C--, because when one is deleted, all the other remaining orders will reduce their index number by one. I don't know if that's the problem here but try it.

Also, it's hard to read your code, use the SRC button when you post.

 

Assuming that the variable Total has been declared.

As it is not assigned a value, probably Total ==0.

In which case

for (int C = 0; C < Total; C ++) 

will do nothing

 
You can use virtual stop loss to beat broker limits.
 
excalibur7:

Hi!

I made a simple internal trailing stop that doesnt work...

I don't want to officially include a stoploss in the order cause they don't allow stoploss below 200points...

<CODE REMOVED>


Please read some other posts before posting . . .

Please edit your post . . . please use the SRC button to post code: How to use the SRC button.


Loops and Closing or Deleting Orders

 
GumRai:

Assuming that the variable Total has been declared.

As it is not assigned a value, probably Total ==0.

In which case

will do nothing


Total was previously declared as : Total = OrdersTotal();!


I've declared it as separate value to be able to work easily with the output!


I will make some research about "virtual stoploss"...<

Thanks a lot!

GAB

 
excalibur7:

Total was previously declared as : Total = OrdersTotal();!


I've declared it as separate value to be able to work easily with the output!

RaptorUK:

Please read some other posts before posting . . .

Please edit your post . . . please use the SRC button to post code: How to use the SRC button.


Loops and Closing or Deleting Orders


 

excalibur7:

I made a simple internal trailing stop that doesnt work...

I don't want to officially include a stoploss in the order cause they don't allow stoploss below 200points...

Here's my unworking script:

  1. So fix your broken code
  2. they certainly do
  3. use SRC
 

Here's my complete script ; it's a simple code that open long transaction when direction of last 15 minutes open are UP, current open (1H) is greather than last 8 open and that short MA is over the long MA 4-8/1H!

My best results are based on AUDCAD for the last year (September to september)...

With 100$ deposit and 50points trailing stop, after a year and 184 transactions, the account show 35000000$.

The problem I have is that the server don't accept TakeProfits or StopLoss under 200Points...

If I put 200points as trailing stop, the Expert is not working anymore so, I need an internal trailing stop that working with 50points...

Here's my winner :

//Global property
double Spread, Lots, MinLots, MaxLots;
int Ticket;
//-----------------------------------------------
 
//Expert Initialisation--------------------------
int start()
 {Spread  = MarketInfo(Symbol(),MODE_SPREAD);
  MinLots = MarketInfo(Symbol(),MODE_MINLOT);
  MaxLots = MarketInfo(Symbol(),MODE_MAXLOT);
  DynamicStop();
  ExpAlloc();
  if (AccountFreeMargin() > (1000 * Lots) && OrdersTotal() == 0 && 
     (DayOfWeek()==0 || DayOfWeek()==6 || Hour()<10 || Hour()>20 || (DayOfWeek()==5 && Hour()>16))) 
   {TradeCheck();
    Sleep(3000);}
  else Sleep(30000);
return(0);}
//-----------------------------------------------

//Exponential Allocation-------------------------
int ExpAlloc()
 {Lots = AccountFreeMargin()/100000*10;
  Lots = MathMin(MaxLots,MathMax(MinLots,Lots));
  if(MinLots<0.1)
   Lots = NormalizeDouble(Lots,2);
   else
    {if(MinLots<1)
     Lots = NormalizeDouble(Lots,1);
     else Lots = NormalizeDouble(Lots,0);}
  if(Lots < MinLots)Lots = MinLots;
  if(Lots > MaxLots)Lots = MaxLots;
return(0);}
//-----------------------------------------------

//Check For Trade--------------------------------
int TradeCheck()
 {double EMASHORT,EMALONG,COPEN,OPEN5M,OPEN10M,CPRICE,PAST1,PAST2,PAST3,PAST4,PAST5,PAST6,PAST7,PAST8;
  EMASHORT = iMA("AUDCAD",PERIOD_H1,4,0,MODE_SMA,1,0);
  EMALONG  = iMA("AUDCAD",PERIOD_H1,8,0,MODE_SMA,1,0);
  COPEN    = iOpen("AUDCAD",PERIOD_M5,0);
  OPEN5M   = iOpen("AUDCAD",PERIOD_M5,1);
  OPEN10M  = iOpen("AUDCAD",PERIOD_M5,2);
  CPRICE   = iOpen("AUDCAD",PERIOD_H1,0);
  PAST1    = iOpen("AUDCAD",PERIOD_H1,1);
  PAST2    = iOpen("AUDCAD",PERIOD_H1,2);
  PAST3    = iOpen("AUDCAD",PERIOD_H1,3);
  PAST4    = iOpen("AUDCAD",PERIOD_H1,4);
  PAST5    = iOpen("AUDCAD",PERIOD_H1,5);
  PAST6    = iOpen("AUDCAD",PERIOD_H1,6);
  PAST7    = iOpen("AUDCAD",PERIOD_H1,7);
  PAST8    = iOpen("AUDCAD",PERIOD_H1,8);
  if (EMASHORT >= EMALONG && COPEN >= OPEN5M && COPEN >= OPEN10M && CPRICE >= PAST1 && 
      CPRICE >= PAST2 && CPRICE >= PAST3 && CPRICE >= PAST4 && CPRICE >= PAST5 && CPRICE >= PAST6 &&
      CPRICE >= PAST7 && CPRICE >= PAST8)
   OpenBuy();
return(0);}   
//-----------------------------------------------

//BUY Position-----------------------------------
int OpenBuy()
 {Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, 0,Ask-200*Point,Ask+500*Point, 0, DodgerBlue);
  if(Ticket>0)
   {if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES))
    {Alert("BUY order opened : ", OrderOpenPrice());
     Print("Buy Signal for : AUD/CAD -- Time Frame : H1 ");}}
return(0);}
//-----------------------------------------------

//Dynamic Stop-----------------------------------
int DynamicStop()
 {double TrailLevel, StopLoss;
  for (int I=-1; I<OrdersTotal(); I++) 
  {OrderSelect(I, SELECT_BY_POS, MODE_TRADES);
   TrailLevel = NormalizeDouble(Bid-(Point*(50+Spread)),Digits);
   if (TrailLevel > StopLoss)
    StopLoss = TrailLevel;
   else if (Bid <= StopLoss)
    {OrderClose(OrderTicket(), OrderLots(), Bid, 0, White);
     StopLoss=0;}}
return(0);}
//-----------------------------------------------
 

100$ to user that solve my problem... instant payment by Paypal!

GAB

 
GumRai:

StopLoss remains==0, so the function will do nothing.


Unfortunatly, it's not the problem...


Stoploss = 0 is only to reset the stoploss value in case of CloseOrder...

If I don't reset the stoploss value, after closeorder, the next order, Bid price is always lower than stoploss and order close right after open and it close/open orders every second...

Maybe that the solution is a refresh rate, an array value or maybe I can use a custom indicator... I will try everything to find a solution to my problem!!!

GAB

Reason: