stop the loop after first five values

1 回表示 (過去 30 日間)
karan goyal
karan goyal 2019 年 2 月 7 日
編集済み: karan goyal 2019 年 2 月 7 日
when a condition is satisfied the loop puts a string value called "buy" in the column but i want to stop that loop upto five "buy" only in the column and then move to the second loop after this is fulfilled.
THE CODE IS AS FOLLOWING:
buycash=0;
sellfut=0;
buylongspread=0;
buy=0;
for ii=1:r
if(ds3.LongAvailableSpread(ii)>=ds3.MeanLongAvailableSpread(ii)&&ds3.LongAvailableSpread(ii)>=40&&ds3.CashBestAskVol(ii)>=3000&&buy==0)
ds3.CashStatus(ii)="buy"; * I WANT UPTO FIVE BUY'S IN THE CASH STATUS
COLUMN WHEN THE ABOVE IF CONDITION IS FULFILLED
AND WHEN IT IS FULFILLED
I WANT TO MOVE TO THE BELOW IF CONDITION*
ds3.FutStatus(ii)="sell";
buylongspread=ds3.LongAvailableSpread(ii);
ds3.CASHPosition_Price(ii)=ds2.CashBestAsk(ii);
buycash=ds2.CashBestAsk(ii);
ds3.FUTPosition_Price(ii)=ds1.FUTBestBid(ii);
sellfut=ds1.FUTBestBid(ii);
buy=1;
end
if ((ds3.ShortAvailableSpread(ii)>=0 || ds3.ShortAvailableSpread(ii)>=40-buylongspread)&&(ds3.CashBestBidVol(ii)>=3000)&&(buy==1))
ds3.CashStatus(ii)="sell";
ds3.FutStatus(ii)="buy";
ds3.CASHPosition_Price(ii)=ds2.CashBestBid(ii);
ds3.FUTPosition_Price(ii)=ds1.FUTBestAsk(ii);
ds3.cashpnl(ii)=ds2.CashBestBid(ii)-buycash;
ds3.futpnl(ii)=sellfut-ds1.FUTBestAsk(ii);
buy=0;
end
end
  2 件のコメント
madhan ravi
madhan ravi 2019 年 2 月 7 日
karan goyal
karan goyal 2019 年 2 月 7 日
EXPLAIN IN THE CODE PLEASE

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeOperators and Elementary Operations についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by