gpt4 book ai didi

string - 当指标缓冲区不再给出值时,我如何保持字符串值不变?

转载 作者:行者123 更新时间:2023-12-04 08:37:14 25 4
gpt4 key购买 nike

我编写了一个基本的“EA 交易”来在参数为真时触发交易。但是,在这种情况下,代码永远不会满足所有要求,因为当指标缓冲区没有给出值时,字符串值也没有给出任何值。
我需要帮助的是为 saisignal 设置字符串值由指标缓冲区触发时保持不变,在柱线通过箭头指标后,以便当其他信号最终指示交易时,它可以触发交易。

double closeAllTradesThisPair()
{
for (int i=OrdersTotal();i>=0;i--)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol())
{
OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),3,clrNONE);
}
}
}

void OnTick()
{
double saiup = iCustom( Symbol(), PERIOD_H1, "super-arrow-indicator", 0, 0 );
double saidn = iCustom( Symbol(), PERIOD_H1, "super-arrow-indicator", 1, 0 );
double osma1 = iOsMA( Symbol(), PERIOD_H1, 12, 26, 9, PRICE_OPEN, 1 );
double osma0 = iOsMA( Symbol(), PERIOD_H1, 12, 26, 9, PRICE_OPEN, 0 );
double stup = iCustom( Symbol(), PERIOD_H1, "super-trend", 0, 0 );
double stdn = iCustom( Symbol(), PERIOD_H1, "super-trend", 1, 0 );
double sar = iSAR( Symbol(), PERIOD_H1, 0.02, 0.2, 0 );
double ma = iMA( Symbol(), PERIOD_H1, 20, 0, MODE_SMA, PRICE_CLOSE, 0 );

string saisignal = "";
string osmasignal = "";
string stsignal = "";
string sarsignal = "";
string masignal = "";

if(saiup < 1000)
{
saisignal = "123";
}
if(saidn < 1000)
{
saisignal = "321";
}

if(osma1 < osma0)
{
osmasignal = "123";
}
if(osma1 > osma0)
{
osmasignal = "321";
}

if(stup < 1000)
{
stsignal = "123";
}
if(stdn < 1000)
{
stsignal = "321";
}

if(sar < Bid)
{
sarsignal = "123";
}
if(sar > Bid)
{
sarsignal = "321";
}

if(ma < Bid)
{
masignal = "123";
}
if(ma > Bid)
{
masignal = "321";
}

for(int b=OrdersTotal()-1;b>=0;b--)
{
if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY)
{
if(OrderStopLoss() < Ask - (150*_Point))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask-(150*_Point),OrderTakeProfit(),0,CLR_NONE);
}
}
if(OrderType()==OP_SELL)
{
if(OrderStopLoss() > Bid + (150*_Point))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid+(150*_Point),OrderTakeProfit(),0,CLR_NONE);
}
}
}
}
}

if(saisignal == "123")
{
if(osmasignal == "123")
{
if(stsignal == "123")
{
if(sarsignal == "123")
{
if(masignal == "123")
{
double buyticket = OrderSend(Symbol(),OP_BUY,0.01,Ask,3,Ask-150*_Point,0,NULL,0,0,CLR_NONE);
}
}
}
}
}

if(saisignal == "321")
{
if(osmasignal == "321")
{
if(stsignal == "321")
{
if(sarsignal == "321")
{
if(masignal == "321")
{
double sellticket = OrderSend(Symbol(),OP_SELL,0.01,Ask,3,Bid+150*_Point,0,NULL,0,0,CLR_NONE);
}
}
}
}
}
Comment(" sai: ",saisignal," osma: ",osmasignal," st: ",stsignal," sar: ",sarsignal," ma: ",masignal);
}

最佳答案

Q : "How do I keep the string value the same...?"


此问题有一个原因和一对可用的解决方案步骤: OnTick(){...}代码按原样,每个条目都会创建空字符串。无论如何,这必须更换。
但是我们必须在某处以某种方式声明这些字符串。
第一个选项
仍然让他们在 {...} 的“范围”( OnTick(){...} )内声明-code-block,但将它们声明为 static string saisignal = ""; // STATIC modifier is key here ,如本例中的 static使编译器将此类声明变量的实际值保持为一个 OnTick(){...}每次都调用另一个(所以永远不要重新声明和重新存储初始化值(这里是一个空的 (string)"")。
    #property strict
...
void OnTick(){
...
static string saisignal = "";
static string osmasignal = "";
static string stsignal = "";
static string sarsignal = "";
static string masignal = "";
...
}
第二种选择
将此类变量声明移至“顶级”范围(对于全局可见变量),这使编译器保留一个永久内存位置来存储和访问任何此类“全局声明/可见”变量。
    #property strict

string saisignal = "";
string osmasignal = "";
string stsignal = "";
string sarsignal = "";
string masignal = "";
...
void OnTick(){
...
}

关于string - 当指标缓冲区不再给出值时,我如何保持字符串值不变?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64742365/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com