Experts: Basic expert adviser with trailing stop

 

Basic expert adviser with trailing stop:

A basic ea template with trailing stop for further development

Basic expert adviser with trailing stop

Author: Kenneth Parling

 
how to install ?? thnks
 
byakuya7773:
how to install ?? thnks

Download the mq4 file and in your terminal open up your experts folder and paste the file to it and restart terminal

File/Open Data Folder/MQL4/Experts


This is not a robot to use for trading as it's only a template for further development purpose.

 

Hi Kenneth 

just wondering if you could help me bit 

i am trying to use this ea but i want to have it decide whether to to go long or short 

and that means changing the way to address the the order currently 

it uses this 

enum OT {_buy,_sell,};

and this 

OT      Ordertype    = _buy;  or we can change it manually to _sell


i have tried several ideas to make it automatic 


//void CheckForOpen()

  //{

   double ma;

   double maLittle;

  // int    res;

//--- go trading only for first tiks of new bar

   if(Volume[0]>1) return;

//--- get Moving Average 

   ma=iMA(NULL,0,MovingPeriod,0,MODE_SMA,PRICE_CLOSE,0);

   

    maLittle=iMA(NULL,0,MovingPeriodshorter,0,MODE_SMA,PRICE_CLOSE,0);

//--- sell conditions

   if((Open[1]>ma && Close[1]<ma)&&(maLittle<ma))

     {

    //  res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,0,0,"",MAGICMA,0,Red);

    

    Ordertype  _sell;

      return;

     }

and it just ingnore me 

can you help please or just point me to where i can find out what i need 

Thnks  Ronk

 
RonkTrader:

Hi Kenneth 

just wondering if you could help me bit 

i am trying to use this ea but i want to have it decide whether to to go long or short 

and that means changing the way to address the the order currently 

it uses this 

enum OT {_buy,_sell,};

and this 

OT      Ordertype    = _buy;  or we can change it manually to _sell


i have tried several ideas to make it automatic 


//void CheckForOpen()

  //{

   double ma;

   double maLittle;

  // int    res;

//--- go trading only for first tiks of new bar

   if(Volume[0]>1) return;

//--- get Moving Average 

   ma=iMA(NULL,0,MovingPeriod,0,MODE_SMA,PRICE_CLOSE,0);

   

    maLittle=iMA(NULL,0,MovingPeriodshorter,0,MODE_SMA,PRICE_CLOSE,0);

//--- sell conditions

   if((Open[1]>ma && Close[1]<ma)&&(maLittle<ma))

     {

    //  res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,0,0,"",MAGICMA,0,Red);

    

    Ordertype  _sell;

      return;

     }

and it just ingnore me 

can you help please or just point me to where i can find out what i need 

Thnks  Ronk

First of all when you post code always use code function Alt + S

code

Secondly, this template adviser was only made to demonstrate it's purpose - the trailing stop! if i understood you right here you want the adviser to either sell or buy depending on you MA signal. To do this you have to completely ignore and remove the manual order selection, totally rebuild the order send functions to make it use both buy/sell depending on signal type plus you need a functional signal module

Good luck

 
great info thanks
 
Kenneth Parling:

First of all when you post code always use code function Alt + S

Secondly, this template adviser was only made to demonstrate it's purpose - the trailing stop! if i understood you right here you want the adviser to either sell or buy depending on you MA signal. To do this you have to completely ignore and remove the manual order selection, totally rebuild the order send functions to make it use both buy/sell depending on signal type plus you need a functional signal module

Good luck

Thanks    I was thinking that might be the case 

i am new to programming   just been doing some arduino programming also based on C++

i like the idea of trailing the stop and also placing a fixed stop just after placing order 

but i have run some of the EAs in this forum and they all seem to lose over time but they work for short periods

cheers Ronk

 

There is a  version upgrade available for this template

Best regards,

Kenneth

Reason: