Download MetaTrader 5

Making an pyramide system together - page 2

To add comments, please log in or register
SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI  
string nokia1 ="newvaluenokia1";

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   double ticksize = MarketInfo(Symbol(),MODE_TICKSIZE);      
   if(ticksize ==0.0001||ticksize ==0.001)
   pips = ticksize * 10;
   else pips = ticksize;
   
   double nokia1 =  GlobalVariableGet(nokia1);
Why do you need to re-use nokia1? Can't you simply make a new variable ?
796790
91
796790  
deysmacro:
Why do you need to re-use nokia1? Can't you simply make a new variable ?


if i change string nokia1 in something else i get next error

'nokia1' - undeclared identifier

whroeder1
15351
whroeder1  
3056527: if i change string nokia1 in something else i get next error 'nokia1' - undeclared identifier
You have to change both of them
string nokia1name ="newvaluenokia1";
:
   double nokia1 =  GlobalVariableGet(nokia1name);
796790
91
796790  

Thanks for explaining.

I think i have right now.

Can somebody tell me if buy1 will be stored in the GVS when i close the computer and buy1 is the same value again when i start the computer up again.

//+------------------------------------------------------------------+
//|                                                 mql4pyramid.mq4 |
//|                                                      |
//|                                         |
//+------------------------------------------------------------------+
#property copyright 
#property link      
#property version   "1.00"
#property strict

double pips;
extern double maxprice = 25;
extern int magicnumber = 100;
double steplevel1 = MarketInfo(Symbol(),MODE_SPREAD);
double trailerpoints1 =MarketInfo(Symbol(),MODE_STOPLEVEL);


double buyorder;
double adjustorder;

double static buy1;

string nokia1 ="newvaluenokia1";

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   double ticksize = MarketInfo(Symbol(),MODE_TICKSIZE);      
   if(ticksize ==0.0001||ticksize ==0.001)
   pips = ticksize * 10;
   else pips = ticksize;
   
   double okia1 =  GlobalVariableGet(nokia1);
   
   buy1 = okia1;
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
AdjustTrail();
  
   int BuyCnt = 0;
  int SellCnt = 0;
  int BuyStopCnt = 0;
  int SellStopCnt = 0;
  int BuyLimitCnt = 0;
  int SellLimitCnt = 0;
  
  int cnt = OrdersTotal();
  for (int i=0; i < cnt; i++) 
  {
    if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
    if (OrderSymbol() != Symbol()) continue;
    if (OrderMagicNumber() != magicnumber) continue;
    
    int type = OrderType();
    if (type == OP_BUY) BuyCnt++;
    if (type == OP_SELL) SellCnt++;
    if (type == OP_BUYSTOP) BuyStopCnt++;
    if (type == OP_SELLSTOP) SellStopCnt++;
    if (type == OP_BUYLIMIT) BuyLimitCnt++;
    if (type == OP_SELLLIMIT) SellLimitCnt++;
   } 
    if(BuyCnt==0)openbuy1();
    
  }
  
//+------------------------------------------------------------------+
void openbuy1 ()
{
double lot = 0.01;
if (Close[0]<maxprice)
buyorder = OrderSend(Symbol(),OP_BUY,lot,Ask,3,0,0,"Buy",magicnumber,Green);
buy1 = Close[0]-steplevel1*pips;
GlobalVariableSet(nokia1,buy1);
}
void AdjustTrail()
{
for(int b = OrdersTotal()-1;b >= 0;b--)
{
if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES))
if(OrderMagicNumber()==magicnumber)
if (OrderSymbol()==Symbol())
if(OrderType()==OP_BUY)
if(Bid-OrderOpenPrice()>(steplevel1+trailerpoints1)*pips)
if(OrderStopLoss()<Bid-pips*(trailerpoints1))
adjustorder = OrderModify(OrderTicket(),OrderOpenPrice(),Bid-(pips*(trailerpoints1)),OrderTakeProfit(),0,CLR_NONE);
if( buy1<OrderTakeProfit())
buy1 = Close[0]-steplevel1*pips;
GlobalVariableSet(nokia1,buy1);
}}
796790
91
796790  

Hello again.

For every new stock with 2 digits

1 change magicnumber

2 set maxprice

3 if using on several stocks(with 2 digits) go into the code and change nokia into boa(use find and replace) and change newvaluenokia in newvalueboa(use find and replace)

4 if you like you can change timechart and maperiod

Still working on this project and any idees are welcom.Hope you like this.

796790
91
796790  
Here is the file.
whroeder1
15351
whroeder1  
3056527: Can somebody tell me if buy1 will be stored in the GVS when i close the computer
Not unless you store it in a GVS and restore it from GVS (in init)
796790
91
796790  

Thanks but if you will check mine code and see if i have did it the right way.

And i made a misstake with the code before here is the right one.

796790
91
796790  

Hello again.

Here is an other update of the pyramid.

If the price has dropped a lot then the lotsize will be more then 0.01 and then you have change to pay swap .

So i changed the program and now it just buy 0.01 lot any time.

If you want to use this program on other symbols then go into the program and use find and replace and change nokia into the symbol you like(only working yet with 2 digits) .

Next thing you have to do is to set your maxprice and change magicnumber.Have fun

Now i have the next question.I would like to use Symbol() instead of nokia but don't know yet how to program this.

Thank you for helping.

string nokia1 ="newvaluenokia1";
string nokia2 ="newvaluenokia2";
string nokia3 ="newvaluenokia3";
string nokia4 ="newvaluenokia4";
string nokia5 ="newvaluenokia5";
string nokia6 ="newvaluenokia6";
string nokia7 ="newvaluenokia7";
12
To add comments, please log in or register