问吧! - 页 34

 
AnasFX:
好的,它成功了,但现在的问题是性能。检查整个历史需要时间。我做了一个一年半的回溯测试,我注意到它很慢。原因是我正在检查历史上的所有订单,比较它们的收盘价和收盘时间。那么,有没有办法限制历史搜索,使其只搜索最近的订单?我可以提高性能吗?

你可以尝试

OrderSelect(HistoryTotal(),SELECT_BY_POS,MODE_HISTORY)。

但我不确定这一点,我想它会选择整个历史中的最后一个订单。

欢呼声

 

大家好...

谁能帮助我...

我有一些指标要创建EA....

 
phoenix:
你可以试试

OrderSelect(HistoryTotal(),SELECT_BY_POS,MODE_HISTORY)。

但我不确定这一点,我想它会选择整个历史中的最后一个订单。

欢呼声

我编辑的错误...它必须是

OrderSelect(HistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY)。

 

抱歉重复发帖,但我真的需要帮助......。

我已经走投无路了。 我整晚都在尝试让我的阵列工作,但什么都没有发生。 我真的尝试过自给自足,并努力学习,但我仍然无法达到我需要的目标。 如果有人能怜悯我,给我一些帮助....PLEASE!!!!!。

我正在运行一个网格脚本,但我想通过Symbol来跟踪我正在运行的手数。 我希望能按手数把我的总头寸加起来。 比方说,我有0.10、0.10、0.10、0.20、0.30,我想知道我有相当于0.90手的仓位。 我还想知道最小和最大手数....0.10和0.30。

ArrayResize(OrderArray, i);

ArrayInitialize(OrderArray,0);

cnt = 0;

for (i = 0; i < OrdersTotal(); i++)

{

if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES) && OrderSymbol() == Symbol() )

{

OrderArray[cnt][PROFIT] = OrderProfit() + OrderSwap();

OrderArray[cnt][OPEN] = OrderOpenPrice();

OrderArray[cnt][LOTS] = OrderLots();

if(OrderType() == OP_BUY)

{

////// I can't get anything to work!!!!!!!

BuyLots += OrderArray[cnt][LOTS];

////// This returns Zero when I place BuyLots in my Comments

////// This returns error messages

MaxBuyLots =ArrayMaximum(OrderArray[LOTS],WHOLE_ARRAY,0);

}

 
deeforex:
对不起,我发了两次帖子,但我真的需要帮助......

我现在很绝望。 我整晚都在尝试让我的阵列工作,但什么都没有发生。 我真的尝试过自给自足,也尝试过学习,但我仍然无法达到我需要的目标。 如果有人能怜悯我,给我一些帮助....PLEASE!!!!!。

我正在运行一个网格脚本,但我想通过Symbol来跟踪我正在运行的手数。 我希望能按手数把我的总头寸加起来。 比方说,我有0.10、0.10、0.10、0.20、0.30,我想知道我有相当于0.90手的仓位。 我还想知道最小和最大手数....0.10 和 0.30。

问题是arrayresize()只调整了第一个元素的大小,而不是第二个。 显然,你的LOTS、PROFIT和OPEN宏必须分别为0、1、2。 另外,for循环中的计数对象是(i),但代码块指的是(cnt).试试这个,看看是否有效。

double OrderArray[][3];

ArrayResize( OrderArray, OrdersTotal() );

cnt = 0;

for (cnt = 0; cnt< OrdersTotal(); cnt++)

{

if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES) && OrderSymbol() == Symbol() )

{

OrderArray[cnt][PROFIT] = OrderProfit() + OrderSwap();

OrderArray[cnt][OPEN] = OrderOpenPrice();

OrderArray[cnt][LOTS] = OrderLots();

if(OrderType() == OP_BUY)

{

double BuyLots;

BuyLots += OrderArray[cnt][LOTS];

MaxBuyLots =ArrayMaximum(OrderArray);

}

 

谢谢Nicholishen。

我越来越接近了。 BuyLots正在返回我想要的东西,但ArrayMaximum给了我一个奇怪的数字,我不太明白。 它没有返回最大的lotSize。

我真的很感谢你的帮助。

dee

 
deeforex:
谢谢Nicholishen。

我越来越接近了。 BuyLots正在返回我想要的东西,但ArrayMaximum却给了我一个奇怪的数字,我不太明白。 它没有返回最大的LotSize。

我真的很感谢你的帮助。

dee

你需要将数组分割成不同的数组,或者写一个循环来提取数组的最大值,例如。

double OrderArray...[];

ArrayResize( OrderArray, OrdersTotal() );

cnt = 0;

for (cnt = 0; cnt< OrdersTotal(); cnt++)

{

if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES) && OrderSymbol() == Symbol() )

{

OrderArrayProfit[cnt] = OrderProfit() + OrderSwap();

OrderArrayOpen[cnt] = OrderOpenPrice();

OrderArrayLots[cnt] = OrderLots();

if(OrderType() == OP_BUY)

{

double BuyLots;

BuyLots += OrderArrayLots[cnt];

MaxBuyLots =ArrayMaximum(OrderArrayLots);

}

[/CODE]

or

[CODE]double OrderArray[][3];

ArrayResize( OrderArray, OrdersTotal() );

cnt = 0;

for (cnt = 0; cnt< OrdersTotal(); cnt++)

{

if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES) && OrderSymbol() == Symbol() )

{

OrderArray[cnt][PROFIT] = OrderProfit() + OrderSwap();

OrderArray[cnt][OPEN] = OrderOpenPrice();

OrderArray[cnt][LOTS] = OrderLots();

if(OrderType() == OP_BUY)

{

double BuyLots;

BuyLots += OrderArray[cnt][LOTS];

}

double MBL;

for(int i=0;i<OrdersTotal();i++){

if(OrderArrayLots[LOTS]>MBL)MBL=OrderArrayLots[LOTS];

}

MaxBuyLots =MBL;

 

这是一个函数 的另一个例子,该函数 通过将追踪数据与相应的交易票号配对,追踪同一货币的多个交易中的紧跟止损--使用数组。 也许这也能给你一些启发。

int tsTicket[21];

double tsPrice[21];

bool tsok[21];

int tkt3[20];

int SuperClose(){// superclose by nicholishen

int cnp=ordercnt();

for(int i=0;i<cnp;i++){

if(OrderMatch(i)){

if(0==0){//Pulls in order that meets the criteria for processing

int num=0;int pos=0;

for(int b=0;b<21;b++){// this (loopB) compares the ticket# of the selected order against the number stored in the ticket array

if(tsTicket==OrderTicket() ){

num++; pos=b;// if ticket numbers match, pos is the position in the array where the trailing data is stored

break;

}

}

if(num==0){ // if the loopB did not find a matching ticket number it is time to initialize the data

for(int j=0;j<21;j++){

if(tsTicket[j]==0){// this is looking for the earliest instance within the array to store the data

pos=j;

break;

}

}

tsTicket[pos]=OrderTicket();// setting the ticket number

tsok[pos]=false;// this is to determine when trailing kicks in

// Print("(",pos,") New ticket initialized = ",tsTicket[pos]);

}

if (OrderType()==OP_SELL) {

if (!tsok[pos] && (OrderOpenPrice()-Ask>=TSactivation*Point || TSactivation==0 ) ) {// if the trailing factor is false, but it has hit the activation point continue

tsPrice[pos]=Ask+TrailPips*Point;// this is the new trailinf stop price

tsok[pos]=true;// it's ok to proceed with trailing stop

if(TrailPips>8){// if this distance from the current price to the new stop, then modify the order.

ModifyStopLoss(Ask+TrailPips*Point,OrderTakeProfit());//modifies order

}

}

if (tsok[pos] && Ask+TrailPips*Point < tsPrice[pos] ){//if the position is gaining in profit

tsPrice[pos]=Ask+TrailPips*Point;

if(TrailPips>8){

ModifyStopLoss(Ask+TrailPips*Point,OrderTakeProfit());

}

}

if (tsok[pos] && Ask >= tsPrice[pos] ){// if the postion hits the stop price

if(CloseOrder(Ask)==STOP)return(STOP);

Print("Short Order ",tsTicket[pos]," Closed from TS");

}

}

else if (OrderType()==OP_BUY) {// reverse of SELL

if(!tsok[pos] && (Bid-OrderOpenPrice() >= TSactivation*Point || TSactivation==0 ) ) {

tsPrice[pos]=Bid-TrailPips*Point;

tsok[pos]=true;

if(TrailPips>8){

ModifyStopLoss(Bid-TrailPips*Point,OrderTakeProfit());

}

}

if (tsok[pos] && Bid-TrailPips*Point > tsPrice[pos] ){

tsPrice[pos]=Bid-TrailPips*Point;

if(TrailPips > 8){

ModifyStopLoss(Bid-TrailPips*Point,OrderTakeProfit());

}

}

if (tsok[pos] && Bid <= tsPrice[pos] ){

if(CloseOrder(Bid)==STOP)return(STOP);

Print("Long Order ",tsTicket[pos]," Closed from TS");

}

}

}

}

if(RefreshRates())return(STOP);

}

for(i=0;i<21;i++){// this searches the array for ticket numbers that are now obsolete due to an order that has closed

if(tsTicket>0){

bool found=false;

for(b=0;b<OrdersTotal();b++){

OrderSelect(b,SELECT_BY_POS);

if(tsTicket==OrderTicket()){

found=true;

break;

}

}

if(!found){// if there are matching ticket numbers in the trade pool and the array then nothing happens

tsTicket=0;tsPrice=0;tsok=false;// if there is an obolete ticket the the data is reset. And the next new ticket data can occupy this space

// Print("Array pos ",i," Cleaned");

}

}

}

return(0);

}

int ordercnt(){

int c;

for(int i=0;i<OrdersTotal();i++){

if(OrderSelect(i,SELECT_BY_POS)){

if(OrderMagicNumber()==ID && OrderSymbol()==Symbol()){

tkt3[c]=OrderTicket();

c++;

}

}

}

return(c);

}

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

int curcnt(){

int c;

for(int i=0;i<OrdersTotal();i++){

if(OrderSelect(i,SELECT_BY_POS)){

if(OrderSymbol()==Symbol()){

c++;

return(c);

}

}

}

return(c);

}

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

bool OrderMatch(int i){

if(OrderSelect(tkt3,SELECT_BY_TICKET)){

if(OrderMagicNumber()==ID && OrderSymbol()==Symbol()){

return(true);

}

}

return(false);

}
 

再次感谢!

我把最后一行中的第3个字改成了这样

if(OrderArray[LOTS]>MBL)MBL=OrderArray[LOTS];

并使之正常工作。 现在已经过了我的睡觉时间。 明天当我醒来时,我将研究你的代码的逻辑。 但因为我很固执,所以我要弄清楚如何使用该死的ArrayMaximum函数!我还得多读一些关于索引的文章。 我还得多读一些关于索引的文章,看看我的老方法是如何错得那么离谱。

再次感谢!!!!

dee

 
deeforex:
再次感谢!

我把最后一行的第3个字改成这样

if(OrderArray[LOTS]>MBL)MBL=OrderArray[LOTS];

并使之正常工作。 现在已经过了我的睡觉时间。 明天当我醒来时,我将研究你的代码的逻辑。 但因为我很固执,所以我要弄清楚如何使用该死的ArrayMaximum函数 我还得多读一些关于索引的文章,看看我的老方法是如何错得那么离谱。

再次感谢!!!!

dee

为了节省你的时间,max函数 之所以不能满足你的要求,是因为你使用的是一个多维数组,你存储的是不同种类的数据。 它将返回这些数据的最大值,所以很可能你返回的是一个利润数字或任何高于你真正的最大手数的数据。