买卖数量不对

//------------------------------------------------------------------------

// 简称: ma123

// 名称: 00000

// 类型: 公式应用

// 类型: 用户应用

// 输出: Void

//------------------------------------------------------------------------


Params

Bool isRollover(False);//是否后复权

Bool isRolloverRealPrice(False);//是否映射真实价格

Bool isAutoSwapPosition(False);//是否自动换仓

Bool ignoreSwapSiganlCalc(False); //是否忽略换仓信号计算

Numeric xma(0);

Vars

Bool bVarCondition_buy_1;

Series<Numeric> sVarCondition_buy_1_left(0,2);

Numeric nVarPlotValue_buy_1_right;

Bool bVarCondition_buy_2;

Series<Numeric> sVarCondition_buy_2_left(0,3);

Series<Numeric> sVarCondition_buy_2_right(0,2);

Bool bVarCondition_buy_3;

Series<Numeric> sVarCondition_buy_3_left(0,3);

Series<Numeric> sVarCondition_buy_3_right(0,2);

Integer iVarSignal_Flag_Buy_1(0);

Numeric dVarPrice_buy_1;

Numeric dVarPrice_buy_1_volume;

Bool bVarCondition_sellShort_1;

Series<Numeric> sVarCondition_sellShort_1_left(0,2);

Numeric nVarPlotValue_sellShort_1_right;

Bool bVarCondition_sellShort_2;

Series<Numeric> sVarCondition_sellShort_2_left(0,3);

Series<Numeric> sVarCondition_sellShort_2_right(0,2);

Bool bVarCondition_sellShort_3;

Series<Numeric> sVarCondition_sellShort_3_left(0,3);

Series<Numeric> sVarCondition_sellShort_3_right(0,2);

Integer iVarSignal_Flag_SellShort_2(0);

Numeric dVarPrice_sellShort_2;

Numeric dVarPrice_sellShort_2_volume;

Numeric mma1(0);

Numeric mma2(0);

Global bool buybool;

Global bool sellbool;

   Global Integer buysellshs(0);

   Global Numeric buyprice;

   Global Numeric sellprice;

   Global Numeric jxi;

     Global String  symbols;

    Array<Integer> orders;

Defs

Numeric Cond_Open(Integer barback = 0)

{

if(Frequency == "tick")

{

return Close[barback];

}

return Open[barback];

}

Integer Cond_round_volume(Numeric volume, Numeric price = 0)

{

Return IntPart(Round(volume / BaseShares(), 0))*BaseShares();

}

Bool Cond_LocalTimeLimit(Numeric bTime, Numeric eTime)

{

If(MakeDateTime(Date(),Time()) >= bTime And MakeDateTime(Date(),Time()) <= eTime)

{

Return True;

}

Return True;

}

Bool buy_condition_1()

{

sVarCondition_buy_1_left = GetPlotNumericValue("MA","MA1");

If(InvalidNumeric() == sVarCondition_buy_1_left[1])

{

Return False;

}

nVarPlotValue_buy_1_right=GetPlotNumericValue("MA","MA1");

If(InvalidNumeric() == nVarPlotValue_buy_1_right)

{

Return False;

}

Return sVarCondition_buy_1_left[1] < nVarPlotValue_buy_1_right;

}

Bool buy_condition_2()

{

sVarCondition_buy_2_left = GetPlotNumericValue("MA","MA1");

If(InvalidNumeric() == sVarCondition_buy_2_left[2])

{

Return False;

}

sVarCondition_buy_2_right = GetPlotNumericValue("MA","MA1");

If(InvalidNumeric() == sVarCondition_buy_2_right[1])

{

Return False;

}

Return sVarCondition_buy_2_left[2] > sVarCondition_buy_2_right[1];

}

Bool buy_condition_3()

{

sVarCondition_buy_3_left = GetPlotNumericValue("MA","MA1");

If(InvalidNumeric() == sVarCondition_buy_3_left[2])

{

Return False;

}

sVarCondition_buy_3_right = GetPlotNumericValue("MA","MA1");

If(InvalidNumeric() == sVarCondition_buy_3_right[1])

{

Return False;

}

Return sVarCondition_buy_3_left[2] == sVarCondition_buy_3_right[1];

}

Bool time_condition_Buy_1()

{

Return Cond_LocalTimeLimit(0, 20250415.222133);

}

Bool sellShort_condition_1()

{

sVarCondition_sellShort_1_left = GetPlotNumericValue("MA","MA1");

If(InvalidNumeric() == sVarCondition_sellShort_1_left[1])

{

Return False;

}

nVarPlotValue_sellShort_1_right=GetPlotNumericValue("MA","MA1");

If(InvalidNumeric() == nVarPlotValue_sellShort_1_right)

{

Return False;

}

Return sVarCondition_sellShort_1_left[1] > nVarPlotValue_sellShort_1_right;

}

Bool sellShort_condition_2()

{

sVarCondition_sellShort_2_left = GetPlotNumericValue("MA","MA1");

If(InvalidNumeric() == sVarCondition_sellShort_2_left[2])

{

Return False;

}

sVarCondition_sellShort_2_right = GetPlotNumericValue("MA","MA1");

If(InvalidNumeric() == sVarCondition_sellShort_2_right[1])

{

Return False;

}

Return sVarCondition_sellShort_2_left[2] < sVarCondition_sellShort_2_right[1];

}

Bool sellShort_condition_3()

{

sVarCondition_sellShort_3_left = GetPlotNumericValue("MA","MA1");

If(InvalidNumeric() == sVarCondition_sellShort_3_left[2])

{

Return False;

}

sVarCondition_sellShort_3_right = GetPlotNumericValue("MA","MA1");

If(InvalidNumeric() == sVarCondition_sellShort_3_right[1])

{

Return False;

}

Return sVarCondition_sellShort_3_left[2] == sVarCondition_sellShort_3_right[1];

}

Bool time_condition_SellShort_2()

{

Return Cond_LocalTimeLimit(0, 20250415.222147);

}

Bool notbuysell()

{

mma1= GetPlotNumericValue("MA","MA1");

mma2= GetPlotNumericValue("MA","MA2");

if(abs(mma2-mma1)<xma)

Return False;

Else

Return True;

}

Events

OnInit()

{

Range[0:DataCount()-1]

{

If(isRollover)

{

AddDataFlag(Enum_Data_RolloverBackWard());

}

If(isRolloverRealPrice)

{

AddDataFlag(Enum_Data_RolloverRealPrice());

}

If(isAutoSwapPosition)

{

AddDataFlag(Enum_Data_AutoSwapPosition());

}

If(ignoreSwapSiganlCalc)

{

AddDataFlag(Enum_Data_IgnoreSwapSignalCalc());

}

}

 symbols=RelativeSymbol();

}

OnBarClose(ArrayRef<Integer> indexs)

{

buysellshs=0;

jxi=0;

buyprice=0;

sellprice=0;

}


OnBar(ArrayRef<Integer> indexs)

{

Range[0:DataCount()-1]

{

bVarCondition_buy_1 = buy_condition_1();

bVarCondition_buy_2 = buy_condition_2();

bVarCondition_buy_3 = buy_condition_3();

dVarPrice_buy_1 = Cond_Open();

dVarPrice_buy_1_volume = Cond_round_volume(1.000000,dVarPrice_buy_1);

    //获取数据源委托映射合约

           //Bool ret = GetLayerOrderMapSymbols(symbols);

          // Print("GetLayerOrderMapSymbols:" + IIFString(ret, "True", "False") + "," + TextArray(symbols));

       

Position pos;

               //获取当前商品的仓位

               //pos.symbol

               bool ret = A_GetPosition(symbols,pos, "", 0);

               Integer buyps=pos.longCurrentVolume;

               Integer sellps=pos.shortCurrentVolume;

               Print("buyps:"+text(buyps));

               Print("sellps:"+text(sellps));

               print("pos:"+pos.symbol);

/*if(buysellshs==0)

{ buybool=False;

 sellbool=False;}

if(buysellshs==1)

{

buybool=true;

sellbool=False;

}

else if (buysellshs==-1)

{sellbool=true;

buybool=False;}*/

if(time_condition_Buy_1() and ( ( bVarCondition_buy_1 and bVarCondition_buy_2 )  or  ( bVarCondition_buy_1 and bVarCondition_buy_3 ) ) and notbuysell and (not buybool) and (buysellshs==0) or buysellshs==1)

{   if(jxi==0)

{

buyprice=dVarPrice_buy_1;

}

 

  jxi=jxi+1;

  buysellshs=1;

  if(pos.longCurrentVolume<=0)

  {

Buy(1,0,iVarSignal_Flag_Buy_1);

}

/*if(pos.shortCurrentVolume>0 and jxi==4)

 {  

 

  //Bool ret = A_BuyToCover(pos.symbol, pos.shortCurrentVolume,close(),orders,"","");

  }*/

}

bVarCondition_sellShort_1 = sellShort_condition_1();

bVarCondition_sellShort_2 = sellShort_condition_2();

bVarCondition_sellShort_3 = sellShort_condition_3();

dVarPrice_sellShort_2 = Cond_Open();

dVarPrice_sellShort_2_volume = Cond_round_volume(1.000000,dVarPrice_sellShort_2);

if(buysellshs==0)

{ buybool=False;

 sellbool=False;}

if(buysellshs==1)

{

buybool=true;

sellbool=False;

}

else if (buysellshs==-1)

{sellbool=true;

buybool=False;}

if(time_condition_SellShort_2() and ( ( bVarCondition_sellShort_1 and bVarCondition_sellShort_2 )  or  ( bVarCondition_sellShort_1 and bVarCondition_sellShort_3 ) ) and (buysellshs==0) or buysellshs==-1)

{   buysellshs=-1;

if(jxi==0)

{

sellprice=dVarPrice_buy_1;

 }

  jxi=jxi+1;                

                   

  if(pos.shortCurrentVolume<=0)

  {

SellShort(1,0,iVarSignal_Flag_SellShort_2);

}

 /*if(pos.longCurrentVolume>0 and jxi==4)

 {

  //A_sell(pos.symbol, pos.longCurrentVolume,close,orders,"","");

  }*/

 

}

}

}


//------------------------------------------------------------------------

// 编译版本: 2025/03/15 222638

// 版权所有 yvhccss

// 更改声明 TradeBlazer Software保留对TradeBlazer平台

// 每一版本的TradeBlazer公式修改和重写的权利

//------------------------------------------------------------------------

换月仓位不对
实际代码是先买卖后赋值 还是先赋值后买卖 哪样代码会更准确些了
)挎号不对,是照着视频例子看的。怎么就不对呢
你好更改买卖手数怎么改
K线数量及信号数量问题
委托数量错误
乖离率买卖点公式如何写
计算金叉数量
跨周期数据不对
关于建仓数量总是大于可开仓数量的问题,困扰很久,迫切向大神求教

最快的路径就是打开监控器,看下持仓是否匹配

然后你这个下单的语句是你代码哪句?