• Home
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • User/Email: Password:
  • 3:51pm
Menu
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • 3:51pm
Sister Sites
  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Options

Bookmark Thread

First Page First Unread Last Page Last Post

Print Thread

Similar Threads

Swing it baby ;-) 24 replies

Baby's 5 min system Trading Journal 3 replies

Baby Sitter EA 4 replies

FX Baby Trading Journal 0 replies

  • Platform Tech
  • /
  • Reply to Thread
  • Subscribe
Tags: Baby Steps...
Cancel

Baby Steps...

  • Post #1
  • Quote
  • First Post: Sep 9, 2008 11:32am Sep 9, 2008 11:32am
  •  Rengoku
  • | Joined Aug 2008 | Status: Member | 45 Posts
Hi there everyone… thanks for taking a look!
I’m trying to learn to program and I have a grand plan for what I want to do, but I need to take baby steps to first learn what I’m doing and second to make this thing work!
Currently, I’m wanting to start the trade manually and have the EA automate the Stop Loss, Trailing Stop, and Take Profit. But for the sake of simplicity… I just want it to automate the Stop Loss but for some reason the code is not changing the order or anything... I heard of problems with doing partial automation??? Is this true?
Could someone take a look at my code and tell me what I'm doing wrong?

Inserted Code
extern double SL        = 10;
extern double TS        = 10;
extern double Protect   = 0;
extern double Initial   = 0;
extern double Profit    = 0;
 
int i;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
 
 
//---- 
 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
 
   int cnt, ticket, total;
   {        
    total=OrdersTotal();
    for (cnt=0;cnt<total;cnt++)
    { 
     OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);   
     if(OrderType()<=OP_SELL && OrderSymbol()==Symbol())
        {
            if(OrderType()==OP_BUY)
            {
               if(OrderStopLoss()<0)
                  {
                  OrderModify(OrderTicket(), OrderOpenPrice(), Bid-Point*SL,OrderTakeProfit(),0,CLR_NONE);  
            return(0);
            }
      }
   }
            if(OrderType()==OP_SELL)
            {
               if(OrderStopLoss()<0)
                  {
                  OrderModify(OrderTicket(), OrderOpenPrice(), Bid+Point*SL,OrderTakeProfit(),0,CLR_NONE);  
            return(0);
            } 
            }
         }   
      } 
 
//----
   return(0);
  }


I really appreciate your help!
  • Post #2
  • Quote
  • Sep 9, 2008 12:18pm Sep 9, 2008 12:18pm
  •  trader101
  • | Commercial Member | Joined Dec 2006 | 2,911 Posts
What you are trying to do is an Uncontrolled trailing stop. Is this really what you are designing for? if not, Check the following:
Inserted Code
extern double SL        = 10;
extern double TS        = 10;
extern double Protect   = 0;
extern double Initial   = 0;
extern double Profit    = 0;
 
int i;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
 
 
//---- 
 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
 
   int cnt, ticket, total;
   {        
    total=OrdersTotal();
    for (cnt=0;cnt<total;cnt++)
    { 
     OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);   
     if(OrderType()<=OP_SELL && OrderSymbol()==Symbol())
        {
            if(OrderType()==OP_BUY)
            {
               if(OrderStopLoss()<0) [color=red][i]//OrderStopLoss() is a positive number[/i][/color]
                  {
                  OrderModify(OrderTicket(), OrderOpenPrice(), Bid-Point*SL,OrderTakeProfit(),0,CLR_NONE);  
            return(0);[i][color=#ff0000]//Some broker requires more than 10 pips away from the price..Check your platform.[/color][/i]
            }
      }
   }
            if(OrderType()==OP_SELL)
            {
               if(OrderStopLoss()<0) [color=red][i]//Same as above[/i][/color]
                  {
                  OrderModify(OrderTicket(), OrderOpenPrice(), Bid+Point*SL,OrderTakeProfit(),0,CLR_NONE);  
            return(0); [color=red][i]//Same as above but better to use the Ask than the Bid[/i][/color]
            } 
            }
         }   
      } 
 
//----
   return(0);
  }
 
 
  • Post #3
  • Quote
  • Sep 9, 2008 12:42pm Sep 9, 2008 12:42pm
  •  Rengoku
  • | Joined Aug 2008 | Status: Member | 45 Posts
First… thank you for the reply!!!

My broker does require a 10 pip SL or TP, that why I put in “extern double SL = 10;”

My overall goal is a total automated system, but my start needs to implement a Stop Loss and next a Trailing Stop. I figured I would attempt this as a partial automated system (meaning I will manually place the order, but the EA will do everything else).

The next phase will be take profits at multiple levels a low, middle, and high level Take Profit. Once the middle is reached I thought I would put in a “While” loop so either direction the pair traded it would hit either the low or high.

I put in a “Print” command to see what it was doing… here is the results from that:
Inserted Code
if(OrderStopLoss()<=0)
               Print("Stop loss is... ", OrderStopLoss());
               return(0);

Inserted Code
11:24:42 Protector EURUSD,M5: loaded successfully
11:24:42 Protector EURUSD,M5 inputs: SL=10; TS=10; Protect=0; Initial=0; Profit=0; 
11:24:42 Protector EURUSD,M5: initialized
11:24:44 Protector EURUSD,M5: Stop loss is... 0
11:24:46 Protector EURUSD,M5: Stop loss is... 0
11:24:49 Protector EURUSD,M5: Stop loss is... 0
11:24:49 Protector EURUSD,M5: Stop loss is... 0
11:24:50 Protector EURUSD,M5: Stop loss is... 0
11:24:50 Protector EURUSD,M5: Stop loss is... 0
11:24:51 Protector EURUSD,M5: Stop loss is... 0
11:24:51 Protector EURUSD,M5: Stop loss is... 0
11:24:52 Protector EURUSD,M5: Stop loss is... 0
11:24:52 Protector EURUSD,M5: Stop loss is... 0
11:25:04 Protector EURUSD,M5: Stop loss is... 0
11:25:04 Protector EURUSD,M5: Stop loss is... 0
11:25:05 Protector EURUSD,M5: Stop loss is... 0
11:25:05 Protector EURUSD,M5: Stop loss is... 0
11:25:06 Protector EURUSD,M5: Stop loss is... 0
11:25:07 Protector EURUSD,M5: Stop loss is... 0
11:25:09 Protector EURUSD,M5: Stop loss is... 0
11:25:11 Protector EURUSD,M5: Stop loss is... 0
11:25:11 Protector EURUSD,M5: Stop loss is... 0
11:25:12 Protector EURUSD,M5: Stop loss is... 0

Sorry… forgot to mention that this block…
if(OrderStopLoss()<0)

all I'm trying to do is determine if a Stop Loss has been previously set… so I do not continually reapply a new stoploss on it.
 
 
  • Post #4
  • Quote
  • Sep 9, 2008 12:57pm Sep 9, 2008 12:57pm
  •  trader101
  • | Commercial Member | Joined Dec 2006 | 2,911 Posts
Wow..
You seems to know what your are doing. Sorry if my comments were of no help to you.
Thanks
 
 
  • Post #5
  • Quote
  • Sep 9, 2008 1:00pm Sep 9, 2008 1:00pm
  •  Rengoku
  • | Joined Aug 2008 | Status: Member | 45 Posts
no... no... Your comments are very helpful!

And I really wish I knew what I was doing! Right now I am totally lost as to why this thing is in this loop!

All I am trying to do is a simple SL...
 
 
  • Post #6
  • Quote
  • Sep 9, 2008 9:25pm Sep 9, 2008 9:25pm
  •  achandrasek
  • | Joined Feb 2006 | Status: Member | 476 Posts
Hi,

In Print function, you are using "<=0", but in the rest of the code using only "<0". Just use "==0". Also, I don't understand the reason for "OrderType()<=OP_SELL" in the first "if" statement. Get rid of it (OrdeType is checked later anyway).

Hope this helps.
chandra
 
 
  • Post #7
  • Quote
  • Last Post: Sep 9, 2008 10:25pm Sep 9, 2008 10:25pm
  •  Rengoku
  • | Joined Aug 2008 | Status: Member | 45 Posts
Thank you!

It's not looping anymore.

Now I need to figure out how to put in the Trailing Stop
 
 
  • Platform Tech
  • /
  • Baby Steps...
  • Reply to Thread
0 traders viewing now
Top of Page
  • Facebook
  • Twitter
About FF
  • Mission
  • Products
  • User Guide
  • Media Kit
  • Blog
  • Contact
FF Products
  • Forums
  • Trades
  • Calendar
  • News
  • Market
  • Brokers
  • Trade Explorer
FF Website
  • Homepage
  • Search
  • Members
  • Report a Bug
Follow FF
  • Facebook
  • Twitter

FF Sister Sites:

  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Forex Factory® is a brand of Fair Economy, Inc.

Terms of Service / ©2023