playing with that 100pips code

 

i have been playing with this code to see how far i can take it


but i got myself lost


here


else //close all positions

if ((diClose0<diMA1)){
return(0);
}

if ((diClose0>diMA1)){

return(0);

}


I was trying to make it so i can have the trigger close the open order

and then the ea will open a new order


i will post the whole code i have for it at the moment

if I have broken any rules etc just tell me dont abuse me

Thanks

Ron


i tried to post the code in the src spot but it too big



Files:
 
Tradingjunky:


i tried to post the code in the src spot but it too big

I find you tabbing and { } layout quite hard to follow . . .
 

I hope you take this in the constructive way it's meant . . .

If you want to modify someone else's code the first thing you need to do is understand the code, this can be very challenging with code written by people who have more coding knowledge than you because you may well see functions that you have no idea about . . . but you still need to understand it, so for everything you don't understand you need to look it up, read about it and understand it . . for me to get a basic grasp of what the code you have posted is doing would probably take me 2 hours . . I don't have that time free at the moment. i would need to lok at the original code and compare it to what you posted so I can understand what you added . . . you didn't comment your additions so you make life hard for anyone that wants to help . . .

 
  1. Format code to a standard format so you can read it
    Your code
    int start()
    {
            if(Bars<100)
            {
             Print("bars less than 100");
             return(0);
            }
                  if(lTakeProfit<10){
                   Print("TakeProfit less than 10");
                            return(0);
                                    }
                               if(sTakeProfit<10){
                                   Print("TakeProfit less than 10");
                                            return(0);
                                                  }
    
                       double diClose0=iClose(NULL,15,0);
                       double diMA1=iMA(NULL,5,166,0,MODE_SMA,PRICE_OPEN,0);
                          double diClose2=iClose(NULL,5,0);
                       double diMA3=iMA(NULL,5,34,0,MODE_SMA,PRICE_OPEN,0);
    
                                              if(AccountFreeMargin()<(10*Lots)){
                                              Print("We have no money. Free Margin = ", Ac...
                                                            return(0);
                                                                               }
    
    Type 1
    int start(){
        if (Bars < 100){
            Print("bars less than 100");
            return(0);
        }
        if (lTakeProfit < 10){
            Print("TakeProfit less than 10");
            return(0);
        }
        if (sTakeProfit < 10){
            Print("TakeProfit less than 10");
            return(0);
        }
    
        double diClose0 = iClose(NULL,15,0);
        double diMA1    = iMA(NULL,5,166,0,MODE_SMA,PRICE_OPEN,0);
        double diClose2 = iClose(NULL,5,0);
        double diMA3    = iMA(NULL,5,34,0,MODE_SMA,PRICE_OPEN,0);
    
        if (AccountFreeMargin() < 10*Lots){
            Print("We have no money. Free Margin = ", AccountFreeMargin());
            return(0);
        }
    
    Type 2
    int start()
    {
        if(Bars<100)
        {
            Print("bars less than 100");
            return(0);
        }
        if(lTakeProfit<10)
        {
            Print("TakeProfit less than 10");
            return(0);
        }
        if(sTakeProfit<10)
        {
            Print("TakeProfit less than 10");
            return(0);
        }
    
        double diClose0=iClose(NULL,15,0);
        double diMA1=iMA(NULL,5,166,0,MODE_SMA,PRICE_OPEN,0);
        double diClose2=iClose(NULL,5,0);
        double diMA3=iMA(NULL,5,34,0,MODE_SMA,PRICE_OPEN,0);
    
        if(AccountFreeMargin()<(10*Lots))
        {
            Print("We have no money. Free Margin = ", AccountFreeMargin());
            return(0);
        }
    
  2. else //close all positions
      if ((diClose0<diMA1)){
        return(0);
      }
      if ((diClose0>diMA1)){
        return(0);
      } 
    In either case you are returning so NONE of the code below will ever be executed. Change you logic to Decide direction, close other direction, open new direction.
    if (diClose0 > diMA1){
       CloseAll(OP_SELL);
       OpenBuy();
    else{
       CloseAll(OP_BUY);
       OpenBuy();
    }
    :
    void CloseAll(int op){
        for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if (
            OrderSelect(pos, SELECT_BY_POS)                 // Only my orders w/
        &&  OrderMagicNumber()  == magic.number             // my magic number
        &&  OrderSymbol()       == Symbol()                 // and my pair.
        && (OrderType()         == OP || OP < 0)
        ){
            if (OrderType > OP_SELL){ // Delete pending orders
               if (!OrderDelete ...) Alert(...
            else{
                RefreshRate(); // Required for multiple closes.
                if(!OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 5*pips2dbl, Aqua))
                    Alert("OrderClose failed: ", GetLastError());
             }
        }
    }
    
  3. Use a magic number in your OrderSend, OrderSelect loops and in bool ExistPositions()
 
WHRoeder:
  1. Format code to a standard format so you can read it
    Your code
    Type 1
    Type 2
  2. In either case you are returning so NONE of the code below will ever be executed. Change you logic to Decide direction, close other direction, open new direction.
  3. Use a magic number in your OrderSend, OrderSelect loops and in bool ExistPositions()

Thankyou for your comments it is helpful to me


I did a course inn coding 10 Vids by Steve Fletcher

i thought it was an ok course but it leaves a lot out

I tried to get him to coach me a bit but he not answer emails

i also find the examples in this website hard to follow

I am improving and I am getting code to compile faster now

but I still dont understand a lot of what is going on

So i gues i just hacking others code mostly

i have written some comparison type code ok but i am getting lost in what information is passed on through the program and what is kept within the function


any way your reply has been helpful I will let you know if i succeed

thanks to you and raptor

Reason: