Forex



Go Back   Forex Trading > Programming > Metatrader Programming






Register in Forex TSD!
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time).
Click here to register and get more information

Reply
 
Thread Tools Display Modes
  #961 (permalink)  
Old 05-27-2008, 04:50 PM
Member
 
Join Date: Oct 2006
Posts: 80
Big Be is on a distinguished road
MoveStopOnce

I have had this problem.
I think you need to add:
if (OrderType() == OP_BUY)

AND use OP_SELL for the sell code.

Big Be
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #962 (permalink)  
Old 05-27-2008, 05:25 PM
matrixebiz's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 1,215
matrixebiz is on a distinguished road
Quote:
Originally Posted by Big Be View Post
I have had this problem.
I think you need to add:
if (OrderType() == OP_BUY)

AND use OP_SELL for the sell code.

Big Be
Ok, I'll try it when I get home but then why does it still work with Buy orders already?
Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #963 (permalink)  
Old 05-27-2008, 10:05 PM
Member
 
Join Date: Oct 2006
Posts: 80
Big Be is on a distinguished road
Quote:
Originally Posted by matrixebiz View Post
Ok, I'll try it when I get home but then why does it still work with Buy orders already?
Thanks
You could be in a Sell order, but the price meets the condition for the Buy stop change code, so it gets changed, and no longer meets the conditions for the Sell section, so it doesn't get changed there.

Big Be
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #964 (permalink)  
Old 05-27-2008, 10:30 PM
matrixebiz's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 1,215
matrixebiz is on a distinguished road
Thanks Big Be for your help but I just realized that my old code does work but I have to enable the use of a StopLoss for SELL orders to get modified..

Wierd, that I don't need to enable a TakeProfit for MoveStopOnce to work with a BUY order but I have to enable a StopLoss for MoveStopOnce to modify the SELL order.

Oh, well, I'll have to look at the code a little deeper to figure that one out unless you know why.


EDIT: if you change to;
Code:
if(0 < OrderOpenPrice() - Point * MoveStopTo) {
instead of;
Code:
if(OrderStopLoss() < OrderOpenPrice() - Point * MoveStopTo) {
Seems to work good.

Thanks

Last edited by matrixebiz; 05-27-2008 at 11:11 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #965 (permalink)  
Old 05-28-2008, 12:55 AM
seawolf's Avatar
Junior Member
 
Join Date: Jul 2007
Posts: 3
seawolf is on a distinguished road
Exclamation Need Help with Position Sizing Calculator

OK,
so I'm building a Position Sizing calculator as a function based on the "Kelly Formula"

(Win Rate-((1-Win Rate)/(Avg Win/Avg Loss)

I've got the over all code and calculations working with manual inputs (extern) for the required variables and am now trying to get the function working dynamically by calling certain account information (namely I want to calculate the Winning consistency rate (%), the avg # pips per winning trade, and the avg # pips per lossing trade)

I could use any and all help getting the three functions (WinRate AvgWin & AvgLoss) operating. I have been using the manual input variation for months and it works great. Here is the complete code for this (automated) version to this point... in testing I am getting no dynamic output, everything goes back to the default setting (50, 40, 20). I have this set up as it's own EA for testing and easy modularization into any existing EA. once attached to any chart, the output is printed in the log/expert tab. the use of fractals is intentional so that maximum account growth (or minimal loss) is exploited. as a note most Brokers offering the MT trader platform allow fractal trading for either mini or std lots. This will prove use full in the future with money management that can take off partial lot positions (ie: remove 25% of 1 Lot). anyway...

in order to collect the real time account info I need I am trying to...
1. count all trades
2. count trades that are profitable
etc. etc.

I may or may not be going about this the right way.


Thanks in advance for all the help...
SeaWolf







//+------------------------------------------------------------------+
//| KellyFormula.mq4 |
//+------------------------------------------------------------------+
#property copyright "seawolf"
#property link "seawolf"
//+------------------------------------------------------------------+
//| EXTERNAL INFORMATION INPUT |
//+------------------------------------------------------------------+
extern int MyAccount = 1001; //------>>>> Account ID
extern int ExpertID = 500001; //------>>>> Magic Number for this EA

extern double PipValue= 1.00; //------>>>> use for ALL calc's
extern double LotCost= 50.0; //------>>>> use for ALL calc's
extern double PercentMax= 24.0; //------>>>> max % account leveraged @ one time
extern int TradesMax= 3; //------>>>> max simultaniouse trades (example: 24%/3 trades = 8% per trade)

extern bool UseKelly= true; //------>>>> Manual overide toggle
extern double ManualLots= 1.0; //------>>>> # lots if "UseKelly" is false
extern double mWinRate= 50.00; //------>>>> winning consistancy in % (manual overide)
extern int mAvgWin= 40; //------>>>> avg # pips per winning trade (manual overide)
extern int mAvgLoss= 20; //------>>>> avg # pips per lossing trade (manual overide)


//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----

PositionSize();
{
Print("Lots=",PositionSize()," WinRate=",WinRate()," AvgWin=",AvgWin()," AvgLoss=",AvgLoss());
}

Comment("Current Time is ",TimeToStr(TimeCurrent(),TIME_MINUTES)," GMT ",TimeToStr(TimeCurrent(),TIME_DATE)," ... Win Rate= ",WinRate()," Avg Win= ",AvgWin()," Avg Loss= ",AvgLoss());

//----
return(0);
}
//----
//+------------------------------------------------------------------+
//| CALCULATE POSITION SIZE FOR ALL NEW TRADES |
//+------------------------------------------------------------------+
//------------------------>>>>
double PositionSize()
{
//------------------------>>>> DO NOT USE KELLY FORMULA, USE FLAT RATE
if(UseKelly == true)
{
double KelyForm = WinRate()-((1-WinRate())/(AvgWin()/AvgLoss()));
double PerTrade;
double Lots;

if(KelyForm > PercentMax)
{
PerTrade = (PercentMax/10)/TradesMax;
}
else if(KelyForm < PercentMax)
{
PerTrade = (KelyForm/10)/TradesMax;
}
else if(KelyForm == PercentMax)
{
PerTrade = (KelyForm/10)/TradesMax;
}
Lots = (PerTrade * AccountBalance()/LotCost);
return(MathRound(Lots)/10);
}
}

//+------------------------------------------------------------------+
//| COLLECT REAL TIME ACCOUNT INFO |
//+------------------------------------------------------------------+
//------------------------>>>>
double WinRate()
{
double Ticket;
double CountWins = 0;

for(Ticket=0;Ticket<OrdersTotal();Ticket++)
{
OrderSelect(Ticket,SELECT_BY_TICKET,MODE_HISTORY);
if(MyAccount==AccountNumber() && OrderSymbol()==Symbol() && OrderMagicNumber() == ExpertID)
{
//------>>>>
if(OrderType()==OP_BUY)
{
if(OrderClosePrice() >= OrderOpenPrice())
CountWins++;
}
else if(OrderType()==OP_SELL)
{
if(OrderClosePrice() <= OrderOpenPrice())
CountWins++;
}
}
}
if(CountWins > 0)
return(MathRound(CountWins/OrdersHistoryTotal())*10);
else
Print("Real Time WinRate not Available");
return(mWinRate);
}
//------>>>>
//------------------------>>>>
double AvgWin()
{
double Ticket;
double CountTrades = 0;
double CountPips = 0;

for(Ticket=0;Ticket<OrdersTotal();Ticket++)
{
OrderSelect(Ticket,SELECT_BY_TICKET,MODE_HISTORY);
if(MyAccount==AccountNumber() && OrderSymbol()==Symbol() && OrderMagicNumber() == ExpertID)
{
//------>>>>
if(OrderType()==OP_BUY && OrderClosePrice()>=OrderOpenPrice())
CountTrades++;
{
if(OrderProfit() >= 0)
CountPips++;
}
if(OrderType()==OP_SELL && OrderClosePrice()<=OrderOpenPrice())
CountTrades++;
{
if(OrderProfit() >= 0)
CountPips++;
}
}
}
if(CountPips > 0)
return(MathRound(CountPips/CountTrades)*10);
else
Print("Real Time AvgWin not Available");
return(mAvgWin);
}

//------>>>>
//------------------------>>>>
double AvgLoss()
{
double Ticket;
double CountTrades = 0;
double CountPips = 0;

for(Ticket=0;Ticket<OrdersTotal();Ticket++)
{
OrderSelect(Ticket,SELECT_BY_TICKET,MODE_HISTORY);
if(MyAccount==AccountNumber() && OrderSymbol()==Symbol() && OrderMagicNumber() == ExpertID)
{
//------>>>>
if(OrderType()==OP_BUY && OrderClosePrice()<OrderOpenPrice())
CountTrades++;
{
if(OrderProfit() < 0)
CountPips++;
}
if(OrderType()==OP_SELL && OrderClosePrice()>OrderOpenPrice())
CountTrades++;
{
if(OrderProfit() < 0)
CountPips++;
}
}
}
if(CountPips > 0)
return(MathRound(CountPips/CountTrades)*10);
else
Print("Real Time AvgLoss not Available");
return(mAvgLoss);
}

//---------------------------------------------------------------------+

Last edited by seawolf; 05-28-2008 at 04:11 AM. Reason: title error
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #966 (permalink)  
Old 05-28-2008, 04:46 AM
Member
 
Join Date: Oct 2006
Posts: 80
Big Be is on a distinguished road
To: Matrixebiz

Quote:
EDIT: if you change to;
Code:
if(0 < OrderOpenPrice() - Point * MoveStopTo) {
instead of;
Code:
if(OrderStopLoss() < OrderOpenPrice() - Point * MoveStopTo) {
Seems to work good.

Thanks

You are welcome.

Big Be

Last edited by Big Be; 05-28-2008 at 04:50 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #967 (permalink)  
Old 05-28-2008, 05:00 AM
hansen_hardrocker's Avatar
Junior Member
 
Join Date: May 2008
Posts: 16
hansen_hardrocker is on a distinguished road
Fxpro,ask

hi all.. i juz want to ask about how to configure lots EA in FxPro..

i confused because it has 6 digits (1 digit extra) i fixed the S/L and T/P but i cant change the lot..

always 0.4 per trade.. even i change it to 0.1 or 0.3

i used 10points 3 EA..


Please Help Me.. email me at hansen_hardrocker@yahoo.co.id

or can PM please..


cheerz all..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #968 (permalink)  
Old 05-28-2008, 05:02 AM
hansen_hardrocker's Avatar
Junior Member
 
Join Date: May 2008
Posts: 16
hansen_hardrocker is on a distinguished road
Ask_change Lot (fxpro)

Fxpro,ask
hi all.. i juz want to ask about how to configure lots EA in FxPro..

i confused because it has 6 digits (1 digit extra) i fixed the S/L and T/P but i cant change the lot..

always 0.4 per trade.. even i change it to 0.1 or 0.3

i used 10points 3 EA..


Please Help Me.. email me at hansen_hardrocker@yahoo.co.id

or can PM please..


cheerz all..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #969 (permalink)  
Old 05-28-2008, 05:38 AM
Junior Member
 
Join Date: Feb 2007
Posts: 6
ramin123 is on a distinguished road
i want it too.please send me at omidchart@yahoo.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #970 (permalink)  
Old 05-28-2008, 11:48 AM
matrixebiz's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 1,215
matrixebiz is on a distinguished road
It probably because you have Money Management enabled in the EA.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
Reply

Bookmarks

Tags
#include, candle time, CHinGsMAroonCLK, code, coders guru, conditionally, dll, eli hayun, Eur_harvester.ex4, expert adviser, expert advisor, forex, higher high, how to code, indicator, I_XO_A_H, kehedge, mechanical trading, metatrader command line, mt4, MT4-LevelStop-Reverse, OrderReliable.mqh, programming, rectangle tool, trading, volty channel stop

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to code this? iscuba11 Metatrader 4 mql 4 - Development course 1 08-03-2007 05:22 PM


All times are GMT. The time now is 02:48 AM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.